私の角度のプロジェクトでは、私は次があります。角度オブジェクトは、未定義
TS
this.storage.get(item_section).then((value) => {
this.item= value;
console.log(this.item); //The console log gives `["name","item","size"]`
console.log(this.item[1]); //Gives `item` as the console log
});
HTML
<div class="something">{{item}}</div> //Displays "name,item,size"
<div class="something">{{item[1]}}</div> //Gets Undefined error
私はthis.item
を定義して得ることができる場合の結果について{{item}}
、どうして{{item[1]}}
の定義されていないエラーが発生しますか?
私はそれはそれはここでは正常に動作し、静的なデータのために働く必要があります
あなたのコード非同期。考えてみてください – yurzui
'item'は非同期操作が終了したときにのみ割り当て可能です。 'this.item = this.storage.get(item_section);'とテンプレート: '{{resolvedItem[1]}} ng-container>のように、 > ' –
developer033
なぜ起こったのか知りたい場合は、[**この質問**]を見ることができます(https://stackoverflow.com/questions/23667086/why-is-my-variable-unaltered-after-i-それは機能の中で非同期#23667087)。 – developer033