CookieXSRFStrategy 在 AOT 模式下不工作@angular
CookieXSRFStrategy not working in AOT mode @angular
我在 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: '/order/' },
{ provide: XSRFStrategy, useValue: cookieStrategy },
{ provide: RequestOptions, 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, useValue: '/order/' },
{ provide: XSRFStrategy, useFactory: cookieStrategy },
{ provide: RequestOptions, useClass: DefaultRequestOptions }
],
我在 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: '/order/' },
{ provide: XSRFStrategy, useValue: cookieStrategy },
{ provide: RequestOptions, 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, useValue: '/order/' },
{ provide: XSRFStrategy, useFactory: cookieStrategy },
{ provide: RequestOptions, useClass: DefaultRequestOptions }
],