错误中的错误遇到静态解析符号值。在 angular 的应用程序模块中

ERROR in Error encountered resolving symbol values statically. in appmodule in angular

我正在尝试在应用程序启动前读取 angular 中的配置文件。我遇到了一个解决方案,但是当我第一次使用 commang ng serve 时,我一直收到错误消息。然后我重新保存代码,webpack 编译成功,没有错误。代码工作正常。 错误是

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 117:45 in the original .ts file), resolving symbol AppModule in C:/Repo/rvm-web-ui/AdaRvmWebClient/src/app/app.module.ts

我添加的行 appmodule.ts

 AppConfig,
    { provide: APP_INITIALIZER, useFactory: (config: AppConfig) => () => config.load(), deps: [AppConfig], multi: true },

和 appconfig 文件

import { Inject, Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { Observable } from 'rxjs/Rx';
import { ConnectionHelper } from 'app/config/connections';

@Injectable()
export class AppConfig {

    private config: Object = null;
    private env:    Object = null;

    constructor(private http: Http) {

    }

    /**
     * Use to get the data found in the second file (config file)
     */
    public getConfig(key: any) {
        return this.config[key];
    }

    /**
     * Use to get the data found in the first file (env file)
     */
    public getEnv(key: any) {
        return this.env[key];
    }

    /**
     * This method:
     *   a) Loads "env.json" to get the current working environment (e.g.: 'production', 'development')
     *   b) Loads "config.[env].json" to get all env's variables (e.g.: 'config.development.json')
     */
    public load() {
        return new Promise((resolve, reject) => {
            this.http.get('conf/env.json').map( res => res.json() ).catch((error: any):any => {
                console.log('Configuration file "env.json" could not be read');
                resolve(true);
                return Observable.throw(error.json().error || 'Server error');
            }).subscribe( (envResponse:any) => {
                this.env = envResponse;
                let request:any = null;

                switch (envResponse.env) {
                    case 'production': {
                        request = this.http.get('conf/config.' + envResponse.env + '.json');
                    } break;

                    case 'development': {
                        request = this.http.get('conf/config.' + envResponse.env + '.json');
                    } break;

                    case 'default': {
                        console.error('Environment file is not set or invalid');
                        resolve(true);
                    } break;
                }

                if (request) {
                    request
                        .map( res => res.json() )
                        .catch((error: any) => {
                            console.error('Error reading ' + envResponse.env + ' configuration file');
                            resolve(error);
                            return Observable.throw(error.json().error || 'Server error');
                        })
                        .subscribe((responseData:any) => {
                            ConnectionHelper.SERVER_IP = responseData.server;
                            ConnectionHelper.SERVER_PORT = responseData.port;
                            ConnectionHelper.SERVER_URL = ConnectionHelper.SERVER_IP+":"+ConnectionHelper.SERVER_PORT+ConnectionHelper.ADA_URL;
                            resolve(true);
                        });
                } else {
                    console.error('Env config file "env.json" is not valid');
                    resolve(true);
                }
            });

        });
    }
}

看起来使用函数定义或 lamda 函数已被弃用。 我需要从应用程序模块中提取函数并在 AppConfig.ts 中定义它(您可以在任何文件中定义它)

export function initConfig(config: AppConfig){
    return () => config.load() 
   }

然后更改了app模块

 AppConfig,
    { provide: APP_INITIALIZER, useFactory: initConfig, deps: [AppConfig], multi: true },

我希望这对某人有帮助