【发布时间】:2017-09-14 14:10:55
【问题描述】:
我将 angular2 与 django rest Api 一起使用。我正在尝试使用以下代码中的服务中的 http get 检索帐户:
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')});
}
【问题讨论】:
标签: angular django-rest-framework