来自前端初学者的问题。我想将 csrf 令牌添加到前端应用程序中的某些请求中。该应用程序在版本 12.2.17 中使用 Angular。我遵循 Angular 文档中的说明:https://angular.io/api/common/http/HttpClientXsrfModule
在代码中我添加拦截器如下:
import {HTTP_INTERCEPTORS, HttpClientModule, HttpClientXsrfModule } from "@angular/common/http";
imports: [
...
HttpClientXsrfModule
],
providers: [
...
{ provide: HTTP_INTERCEPTORS, useExisting: HttpXsrfInterceptor, multi: true }
],
当我这样做时,带有“HttpXsrfInterceptor”的行会触发 IntelliJ 中的错误工具提示:
TS2552: Cannot find name HttpXsrfInterceptor . Did you mean HTTP_INTERCEPTORS ?
我应该更改什么才能正确配置 HttpXsrfInterceptor?
请更新以下行!
import {HTTP_INTERCEPTORS, HttpClientModule, HttpClientXsrfModule, HttpXsrfInterceptor } from "@angular/common/http";