2017-04-18 4 views
2

장고용 휴식 Api와 함께 angular2를 사용하고 있습니다. 울부 짖는 코드에서 서비스에 HTTP GET을 사용하여 계정을 검색하려고하면 :Django rest angular2 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')}); 
} 

나는 확인 HTTP 만에 응답을 얻었다 당신은 return 누락 enter image description here

답변

3

, 당신의 반응은 그래서 data을 가지고

을하지 않는 것 : 구성 요소의 계정이 정의되어 있지 않습니다
.then(response => { response.json().data }) 

가 있어야한다 :

.then(response => { return response.json() }) 
+1

예 효과적으로 내가 수익을 놓친 유 너무 감사합니다 – sila