일부 게시물에 따르면, 내 angular2 앱에서 config.json 파일을로드하려고했지만 위의 오류가 프론트 엔드에 있습니다.Angular2로 config.json로드 : NoProviderError.ZoneAwareError에서 DI 오류
응용 프로그램 \이
import { ConfigService } from './service/config-service';
@NgModule({
providers: [
{ provide: APP_INITIALIZER, useFactory: (config: ConfigService) =>() => config.load(), deps: [ConfigService], multi: true }
]
})
응용 프로그램 \ 서비스 \의 설정 - service.ts에게
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { Observable } from 'rxjs/Rx';
import 'rxjs/add/operator/map';
@Injectable()
export class ConfigService {
private _config: Object;
constructor(private http: Http) {
console.log("Config Created");
}
load() {
// Get the Config
return new Promise(function(fulfill, reject) {
// Get the conf
this.http.get('/app/config.json') // path of your config.json file
.map(res => res.json())
.subscribe(config => {
this._config = config;
fulfill(true);
});
});
}
getCentralSystemServer() {
return this._config["CentralSystemServer"];
}
}
나를 보자을 app.module.ts : 내가 한 일을 여기
같은 종류의 문제가 발생했는지 확인하십시오.
감사합니다. Serge.
그냥 질문, 아래 서비스를 구성하지 않았기 때문에 왜'대신'Observable'의 부하()'에 대한 약속을 반환합니까? –
사실, Observable을 사용할 수 있었지만 다른 스레드에서이 코드를 가져 와서 바로 사용했습니다 :-). 그리고 또한 nodejs와 angularjs 사이에서도 저글링을하고 있습니다 ;-). – LucasBrazi06