我是Angular2的新手并尝试运行本教程.它使用a fakeBackendProvide
来模拟后端调用MockBackend
.
fackBackend的逻辑是这样的:
export let fakeBackendProvider = {}
index.ts
class有助于导出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
我在同一个教程中遇到了同样的问题.我所做的只是从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