2017-03-28 19 views
5

我爲XSRFStrategyapp.module.tsCookieXSRFStrategy不是在AOT模式@angular

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

做工精細用手錶提供CookieXSRFStrategy工作/服務於第二內建但--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

納克--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 

回答

9

回答我的問題,發現我不得不使用導出函數的引用,因此使用這樣的:

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

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

編譯好,但正在給運行時錯誤:爲

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 } 
    ], 
+1

這是黃金。你也應該接受答案。 –

相關問題