Skip to content

Instantly share code, notes, and snippets.

@deksoke
Last active March 14, 2019 17:47
Show Gist options
  • Save deksoke/c4bdf1f354bd4b91fabee79184ef936e to your computer and use it in GitHub Desktop.
Save deksoke/c4bdf1f354bd4b91fabee79184ef936e to your computer and use it in GitHub Desktop.
Custom OData Query String with Http Interceptor
import { Injectable } from '@angular/core';
import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest, HttpErrorResponse, HttpResponse } from '@angular/common/http';
@Injectable()
export class CustomInterceptor implements HttpInterceptor {
constructor() { }
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (request.params.has('$count')) {
let customParams = request.params.delete('$count');
customParams = customParams.append('$inlinecount', 'allpages');
request = request.clone({ params: customParams });
}
return next.handle(request);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment