It works fine in injecting into components. problem occurs in service injection.I am using runtime configuration for end points.it works in components.i can able to change in runtime but throws an error when injecting in other services globalexport class AppConfigService { static settings: IAppConfig;constructor(private http: HttpClient) {}load() { const jsonFile = `../assets/config/config.json`; return new Promise<void>((resolve, reject) => { this.http.get(jsonFile).toPromise().then((response : IAppConfig) => { AppConfigService.settings = <IAppConfig>response; console.log('Config Loaded'); console.log( AppConfigService.settings); resolve(); }).catch((response: any) => { reject(`Could not load the config file`); }); });}}in the app module provide app intializers:providers: [ AppConfigService, { provide: APP_INITIALIZER,useFactory: initializeApp, deps: [AppConfigService], multi: true},export function initializeApp(appConfigService: AppConfigService) { return (): Promise<any> => { return appConfigService.load(); }}when integrate with app service have the error. could not load the config file. But it works in a component.auth.serviceimport { AppConfigService } from 'app/app-config.service';@Injectable({ providedIn: 'root'})export class AuthService { apiServer = AppConfigService.settings.apiServer; constructor(private httpClient: HttpClient) { console.log(this.apiServer.link1); }Reference link :reference urlApp.settings - the Angular way?Loading configuration files in Angular 6Load Config JSON File In Angular 2 解决方案 Hi I have added you an example:https://stackblitz.com/edit/angular-pkuwef?file=src/app/app.module.tshttps://github.com/misanche/angular-pkuwef/ 这篇关于无法在服务中加载配置文件 - 供应商 js 65401的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-02 21:05