Angular 2:从MockBackend静态解析符号值时遇到错误

时间:2017-01-21 16:34:11

标签: angular

我是Angular2的新手,并尝试运行此tutorial。它使用fakeBackendProvide来使用MockBackend模拟后端调用。

fackBackend的逻辑是这样的: export let fakeBackendProvider = {}

index.ts类有助于使用一行导出fackBackendProviderexport * 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

1 个答案:

答案 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