Я только начинаю изучать угловые. У меня проблема при вызове службы в угловом режиме. Служба звонит успешно, но у меня проблема, как я могу обрабатывать данные. В Angular1
мы делаем так:Calling Service в Angular2
DemoService.getExchangeDataConnection().then(function(response){
//here we handle all the data
})
Angular2
constructor(private _sampleService: SampleService){
this._sampleService = _sampleService;
}
onClickMe(){
this.clickMessage ='You are my hero!';
this.error = "";
this.countries = [];
this._sampleService.test()
.subscribe(
data => this.countries = data,
error => this.error = "Region " + this.region + " is invalid."
);
}
здесь Как я могу обрабатывать данные Вот моя служба:
export class SampleService {
constructor(http: Http){
this.http = http;
}
test(){
console.log(AppSettings.API_ENDPOINT);
return this.http.get(AppSettings.API_ENDPOINT+"oceania").toPromise()
.then(res => console.log(res.json()), err => console.log(err));
}
}
Не конвертировать вы HTTP называют пообещать. – Chandermani