angular-httpclient-interceptors

Use a promise in Angular HttpClient Interceptor

血红的双手。 提交于 2019-11-29 11:20:08
问题 Can I use promise within HttpInterceptor ? For example: export class AuthInterceptor implements HttpInterceptor{ this.someService.someFunction() .then((data)=>{ //do something with data and then return next.handle(req); }); } why I need this? because I need to get a token to add to request header before making the request to the server. My interceptor: @Injectable() export class AuthInterceptor implements HttpInterceptor{ constructor(private authService: AuthService){} intercept(req: