我尝试使用新的Angular 4.3
拦截器为所有请求设置authorithation标头.但是,它不起作用.我将断点设置为拦截器intercept
方法,浏览器没有命中它,所以它似乎angular
只是忽略了我的拦截器.请帮助我,提前谢谢.
user.service.ts:
import {Injectable} from '@angular/core';
import 'rxjs/add/operator/map';
import {Observable} from "rxjs";
import {Http} from "@angular/http";
@Injectable()
export class UserService {
constructor(public http: Http) {
}
public getContacts(): Observable<any[]> {
return this.http.get('/users/contacts').map(contacts => contacts.json());
}
}
Run Code Online (Sandbox Code Playgroud)
token.interceptor.ts
import {Injectable} from '@angular/core';
import {
HttpRequest,
HttpHandler,
HttpEvent,
HttpInterceptor
} from '@angular/common/http';
import {Observable} from 'rxjs/Observable';
import {AuthService} from "./shared/auth.service";
@Injectable()
export class TokenInterceptor implements HttpInterceptor {
constructor(public auth: AuthService) {
}
intercept(request: HttpRequest<any>, next: …
Run Code Online (Sandbox Code Playgroud)