简体   繁体   English

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

[英]CookieXSRFStrategy not working in AOT mode @angular

I am providing CookieXSRFStrategy for XSRFStrategy in app.module.ts 我在CookieXSRFStrategyXSRFStrategy提供CookieXSRFStrategy

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

working fine with watch/serve on second build but when building with --prod flag, getting this error: 在第二个版本上与watch / serve一起正常工作,但是在使用--prod标志构建时,出现此错误:

ERROR in Error encountered resolving symbol values statically. ERROR中的ERROR遇到静态解析符号值的错误。 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 考虑使用对导出函数的引用(原始.ts文件中的位置50:34)替换该函数或lambda,在E:/repo/src/app/app.module.ts中解析符号AppModule

ng --version 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

Answering my own question, found that I have to use a reference to an exported function, so using like: 在回答我自己的问题时,发现我必须使用对导出函数的引用,因此使用如下代码:

providers: [
    { provide: APP_BASE_HREF, useValue: '/order/' },
    { provide: XSRFStrategy, useValue: cookieStrategy },
    { provide: RequestOptions, useClass: DefaultRequestOptions }
],

export function cookieStrategy() {
  return  new CookieXSRFStrategy('csrftoken', 'X-CSRFToken');
}

compiled well, but was giving runtime error: as 编译良好,但给出运行时错误:as

ERROR TypeError: this._xsrfStrategy.configureRequest is not a function 错误TypeError:this._xsrfStrategy.configureRequest不是一个函数

changing useValue in provide to useFactory fixed the problem 在为useFactory提供中更改useValue解决了问题

providers: [
    { provide: APP_BASE_HREF, useValue: '/order/' },
    { provide: XSRFStrategy, useFactory: cookieStrategy },
    { provide: RequestOptions, useClass: DefaultRequestOptions }
  ],

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM