Angular Http拦截器不';不要记录任何信息
我已经创建了一个Angular Http拦截器不';不要记录任何信息,angular,http,interceptor,angular-http-interceptors,Angular,Http,Interceptor,Angular Http Interceptors,我已经创建了一个CustomHttpInterceptor,现在我只想记录一些信息,例如: @Injectable() export class CustomHttpInterceptor implements HttpInterceptor { intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { console.log('http in
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);
}
问题是,您需要使用新的(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());
}
}
有关详细指南,请参阅
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());
}
}