2016-09-15 1 views
0

私はこのエラーを得た:escでtypescriptについて私は何をしますか?

[0] app/components/pessoas/detail/PessoaDetailComponent.ts(27,35): error TS2339: Property 'pessoa' does not exist on type '{}'.

コード:

export class PessoaDetailComponent 
    { 
    pessoa: any; 

    constructor(private _api: Api, private _params: RouteParams) 
    { 
     this._api.getPessoa(_params.get("id")).then(
      (res) => { 
    //line 27//  this.pessoa = res.pessoa; 
      }, 
      (error) => { 
       console.error(error); 
      } 
     ) 
     } 
    } 
+0

res.pessoaは何を返しますか?どのタイプの価値ですか? – micronyks

答えて

0

これはタイプに関連する問題です。何らかの理由で、typescriptですがresがタイプ{}であり、従って、pessoaはタイプ

使用

(res: any) => { 
    this.pessoa = res.pessoa; 
}, 

上に存在するか、あなたはそれを知っている場合は、適切なタイプを使用していないと文句を言い思います。

+0

ありがとうございました! –

0

あなたはコンストラクタの内部での約束に連鎖方式にしようとしています。それをしないでください。あなたのthisインスタンスは、約束のためにうんざりしています。

constructor(private _api: Api, private _params: RouteParams) 
{ 
    this.pessoa = this._api.getPessoa(_params.get("id")); 
} 
//anywhere you need to use the pessoa property use this.pessoa.then() 
+0

古いJS方法で 'this'を参照してください:( –

+0

ありがとうございました! –

関連する問題