角度2:从MockBackend静态解析符号值时遇到错误 [英] Angular 2: Error encountered resolving symbol values statically from MockBackend
问题描述
我是Angular2的新手,正在尝试运行此 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文件的链接:tutorial. It uses a fakeBackendProvide
to simulate backend calls using MockBackend
.
Logic for fackBackend goes like this:
export let fakeBackendProvider = {}
index.ts
class helps to export the fackBackendProvider
with one line:
export * from './fake-backend';
app.module.ts
looks like this:
providers: [
AuthGuard,
AuthenticationService,
UserService,
//fake backend providers
fakeBackendProvider,
MockBackend,
BaseRequestOptions
],
I am getting this error message:
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
No idea what is going wrong.
Rest of the code, can be found here: Github
I had the same issue with the same tutorial. What I did was just create a new function from the lambda expression and then just invoked it inside the useFactory in fakeBackendProvider.
export function mockBackEndFactory(backend: MockBackend, options: BaseRequestOptions, realBackend: XHRBackend) { ... }
export let fakeBackendProvider = {
provide: Http,
deps: [MockBackend, BaseRequestOptions, XHRBackend],
useFactory: mockBackEndFactory
};
Here's the link for fake-backend.ts file I modified: https://github.com/cealmees/Angular2-training/blob/master/src/app/entities/login/helpers/fake-backend.ts
这篇关于角度2:从MockBackend静态解析符号值时遇到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!