I have created a CustomHttpInterceptor
which now I would like to just log some info, eg:
@Injectable()
export class CustomHttpInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
console.log('http intercpeotr', req, next)
return next.handle(req);
}
Of course I registred it in providers
in app.module
but nothing has been logged which I did some requests to the server.
My angular
service looks like:
import {Http} from "@angular/http";
getAllWithPaging(params: HttpParams){
return this.http.get(this.url + '/withPaging?' + params.toString());
}
The issue is that you need to use the new HttpClient (Angular 4.3) to do the request (imported from @angular/common/http
instead of the old one imported from @angular/http
.
import { HttpClient, HttpParams } from '@angular/common/http';
@Injectable()
export class MyService {
constructor(private httpClient: HttpClient) {}
getAllWithPaging(params: HttpParams) {
return this.httpClient.get(this.url + '/withPaging?' + params.toString());
}
}
Refer to the official documentation for a detailed guide.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.