加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

CookieXSRFStrategy无法在AOT模式下工作@angular

发布时间:2020-12-17 06:49:08 所属栏目:安全 来源:网络整理
导读:我在app.module.ts中为XSRFStrategy提供CookieXSRFStrategy providers: [ { provide: APP_BASE_HREF,useValue: '/order/' },{ provide: XSRFStrategy,useValue: new CookieXSRFStrategy('csrftoken','X-CSRFToken') },{ provide: RequestOptions,useClass: D
我在app.module.ts中为XSRFStrategy提供CookieXSRFStrategy

providers: [
    { provide: APP_BASE_HREF,useValue: '/order/' },{ provide: XSRFStrategy,useValue: new CookieXSRFStrategy('csrftoken','X-CSRFToken') },{ provide: RequestOptions,useClass: DefaultRequestOptions }
  ],

在第二次构建时使用watch / serve工作正常,但在使用–prod标志构建时,收到此错误:

ERROR in Error encountered resolving symbol values statically.
Function calls are not supported. Consider replacing the function or
lambda with a reference to an exported function (position 50:34 in the
original .ts file),resolving symbol AppModule in
E:/repo/src/app/app.module.ts

ng –version

@angular/cli: 1.0.0
node: 6.9.1
os: win32 x64
@angular/common: 4.0.0
@angular/compiler: 4.0.0
@angular/core: 4.0.0
@angular/forms: 4.0.0
@angular/http: 4.0.0
@angular/platform-browser: 4.0.0
@angular/platform-browser-dynamic: 4.0.0
@angular/router: 4.0.0
@angular/animations: 4.0.0
@angular/cli: 1.0.0
@angular/compiler-cli: 4.0.0

解决方法

回答我自己的问题,发现我必须使用对导出函数的引用,所以使用如下:

providers: [
    { provide: APP_BASE_HREF,useValue: cookieStrategy },useClass: DefaultRequestOptions }
],export function cookieStrategy() {
  return  new CookieXSRFStrategy('csrftoken','X-CSRFToken');
}

编译好,但是给出了运行时错误:as

ERROR TypeError: this._xsrfStrategy.configureRequest is not a function

改变useValue提供useFactory修复问题

providers: [
    { provide: APP_BASE_HREF,useFactory: cookieStrategy },

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读