【问题标题】:ERROR in Error encountered resolving symbol values statically错误中的错误遇到静态解析符号值
【发布时间】:2017-04-29 10:16:51
【问题描述】:

我刚刚在 angular-cli 下迁移了我的项目,当我启动它时出现此错误:

错误中的错误遇到静态解析符号值。 不支持函数调用。考虑更换功能或 lambda 引用导出的函数(位置 63:45 在 原始 .ts 文件),解析符号 AppModule 在 C:/Data/Private/Innovation/EV/ev-dashboard/src/app/app.module.ts

对应app.module.ts下面的APP_INITIALIZER:

...
providers: [ // expose our Services and Providers into Angular's dependency injection
    APP_PROVIDERS,
    ConfigService,
    { provide: APP_INITIALIZER, useFactory: (config: ConfigService) => () => config.load(), deps: [ConfigService], multi: true }
...

有趣的是,当我注释这一行时,它开始很好,然后取消注释,这一次触发编译没有错误!!!

你有什么想法吗?

谢谢, 塞尔吉。

【问题讨论】:

    标签: angular typescript


    【解决方案1】:

    你需要提取如下函数:

    export function configFactory(config: ConfigService) {
      return () => config.load()
    }
    
    ...
    providers: [{ 
      provide: APP_INITIALIZER, 
      useFactory: configFactory, 
      deps: [ConfigService], 
      multi: true 
    }
    

    另见

    【讨论】:

    • 谢谢一百万!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-03
    • 2017-09-06
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 2018-03-22
    • 2017-02-13
    相关资源
    最近更新 更多