2017-10-05 30 views
0

早上好,Angular2值不確定

我有以下問題:

onSubmit(){ 
    this.userService.getCandidate(this.candidate) 
    .subscribe( 
     (candidate) => { 
     this.candidate2 = candidate; 
     console.log(this.candidate2); 
     this.name=this.candidate.name; 
     console.log(this.candidate2.name); 
     }, 
     (error: Response) => console.log(error), 
    ()=> { 
      console.log("Finished")} 
    ) 
} 

console.log(this.candidate2);給了我預期的人選包括所有字段 但console.log(this.candidate2.name);給我不確定。

我該怎麼做,因爲我的候選人的不同領域的價值。

+0

這是什麼候選人?它的模型 – Chandru

+0

你可以更新候選人和有問題的這個.Candidate值嗎? – Chandru

回答

0

事實上的錯誤是從該行

this.name=this.candidate.name; 

改變它作爲

this.name=this.candidate2.name; 

this.name=candidate.name; 

它應該是,

onSubmit(){ 
    this.userService.getCandidate(this.candidate) 
    .subscribe( 
     (candidate) => { 
     this.candidate2 = candidate; 
     console.log(this.candidate2); 
     this.name=this.candidate2.name; 
     console.log(this.candidate2.name); 
     }, 
     (error: Response) => console.log(error), 
    ()=> { 
      console.log("Finished")} 
    ) 
} 
+0

或this.name = candidate.name。 – Wandrille

+0

@Wandrille它已經在那裏答案 – Sajeetharan

+0

Oups,沒有見過。我的錯! – Wandrille