Ich fange gerade an, eckig2 zu erlernen. Ich habe Problem beim Anrufen des Services in angular2.The Serviceanrufe erfolgreich, aber ich habe Problem, wie ich Daten behandeln kann. In Angular1
tun wir wie folgt aus:Anrufdienst in 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."
);
}
hier Wie kann ich Daten umgehen Hier Mein Service:
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));
}
}
nicht umwandeln Sie http versprechen nennen. – Chandermani