订阅中变量的 Angular2 值未定义

Angular2 value of variable in subsrcibe is undefined

早上好,

我遇到以下问题:

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); 给我未定义。

我对一个候选人不同领域的价值怎么办

实际上错误来自这一行

 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")}
      )
}