2017-10-11 104 views
0

我創建了一個CustomHttpInterceptor現在我想只要登錄系統的一些信息,如任何信息:的Http攔截器不記錄

@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); 
    } 

當然我registred它providersapp.module但什麼也沒有記錄我向服務器做了一些請求。

angular服務看起來像:

import {Http} from "@angular/http"; 
getAllWithPaging(params: HttpParams){ 
    return this.http.get(this.url + '/withPaging?' + params.toString()); 
    } 

回答

1

的問題是,你需要使用新的HttpClient(角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進行了詳細的指南。