angular 4.3x dynamic http interceptor

后端 未结 2 2006
轻奢々
轻奢々 2020-12-20 09:00

I followed this article from medium to create a http interceptor which lets me add headers to each http call

@Injectable()
export class TokenInterceptor impl         


        
2条回答
  •  半阙折子戏
    2020-12-20 09:59

    From the article it says:

    It should be noted that Angular’s new HttpClient from @angular/common/http is being used here and not the Http class from @angular/http. If we try to make requests with the traditional Httpclass, the interceptor won’t be hit

    Please make sure you are using import { HttpClient } from '@angular/common/http'; in the import section.

    and then it the constructor use it: constructor(public http: HttpClient) {}

提交回复
热议问题