我创建了一个CustomHttpInterceptor
,现在我只想记录一些信息,例如:
@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);
}
当然我在providers
app.module
注册了它,但没有记录任何内容,我向服务器发出了一些请求。
我的angular
服务如下:
import {Http} from "@angular/http";
getAllWithPaging(params: HttpParams){
return this.http.get(this.url + '/withPaging?' + params.toString());
}
答案 0 :(得分:1)
问题是您需要使用新的HttpClient(Angular 4.3)来执行请求(从@angular/common/http
导入而不是从@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());
}
}
有关详细指南,请参阅official documentation。