我是Angular2的新手,并尝试运行此tutorial。它使用fakeBackendProvide
来使用MockBackend
模拟后端调用。
fackBackend的逻辑是这样的:
export let fakeBackendProvider = {}
index.ts
类有助于使用一行导出fackBackendProvider
:
export * from './fake-backend';
app.module.ts
看起来像这样:
providers: [
AuthGuard,
AuthenticationService,
UserService,
//fake backend providers
fakeBackendProvider,
MockBackend,
BaseRequestOptions
],
我收到此错误消息:
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 7:15 in the original .ts file), resolving symbol fakeBackendProvider in /Users/hyadav/Documents/hp-app/src/app/helpers/fake-backend.ts, resolving symbol fakeBackendProvider in /Users/hyadav/Documents/hp-app/src/app/helpers/index.ts, resolving symbol AppModule in /Users/hyadav/Documents/hp-app/src/app/app.module.ts, resolving symbol AppModule in /Users/hyadav/Documents/hp-app/src/app/app.module.ts
不知道出了什么问题。
其余代码可在此处找到:Github
答案 0 :(得分:6)
我在同一个教程中遇到了同样的问题。我所做的只是从lambda表达式创建一个新函数,然后在fakeBackendProvider中的useFactory中调用它。
export function mockBackEndFactory(backend: MockBackend, options: BaseRequestOptions, realBackend: XHRBackend) { ... }
export let fakeBackendProvider = {
provide: Http,
deps: [MockBackend, BaseRequestOptions, XHRBackend],
useFactory: mockBackEndFactory
};
以下是我修改过的fake-backend.ts文件的链接:https://github.com/cealmees/Angular2-training/blob/master/src/app/entities/login/helpers/fake-backend.ts