当前位置:  开发笔记 > 开发工具 > 正文

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

如何解决《Angular2:从MockBackend静态解析符号值时遇到错误》经验,为你挑选了1个好方法。

我是Angular2的新手并尝试运行本教程.它使用a fakeBackendProvide来模拟后端调用MockBackend.

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

index.tsclass有助于导出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



1> 小智..:

我在同一个教程中遇到了同样的问题.我所做的只是从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

推荐阅读
吻过彩虹的脸_378
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有