2
上午使用angular2與Django rest Api。我試圖在波紋管的代碼服務來檢索使用HTTP GET一筆賬:Django Rest angular2 http獲取
getAccountBackend(id: string) : Promise<any> {
const slash="/"
const urlaccount = `${this.urlAccontBackend}${id}${slash}`;
console.log('url du compte', urlaccount)
return this.http.get(urlaccount)
.toPromise()
.then(response => {
response.json().data
console.log(response)}
)
.catch(this.handleError);
}
當嘗試在組件解決這個方法:
getAccountById(){
console.log("i will resolve the account");
this.fcbAccSrv.getAccountBackend('1234896')
.then(data=> {
this.compte=data
console.log("the account from the backend", this.compte);
})
.catch(error =>{ this.error = error;
console.log('error to resolve account')});
}
是有效的我錯過了回報感謝ü這麼多 – sila