In my angular project, I have the following:
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
If I can define the this.item and get results for {{item}}, how come I get undefined error for {{item[1]}}?
I am little confused to how to fix this
itemis only assignable when the async operation finishes. You can use something like this in component:this.item = this.storage.get(item_section);and in template:<ng-container *ngIf="item | async as resolvedItem"><div class="something">{{resolvedItem[1]}}</div></ng-container>