Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2. Loop of array inside object using ngFor

I have next structure of a component data:

enter image description here

I want to print a list of assignedCards within component's view using *ngFor. I do this possible:

<div *ngFor="#item of mission.assignedCards" class="b-progress-bar__item m-progress-bar__item_completed">
<div class="b-progress-bar__inner">{{item}}</div>
</div>

But it falls with an exception:

enter image description here

If i test mission value, it says me, that mission is an object.

enter image description here

So, i'd like to access assignedCards array inside mission object and make a loop of it.

like image 716
Edward Avatar asked Dec 05 '25 10:12

Edward


1 Answers

I guess that the mission object is loaded asynchronously. So it's undefined at a first time and is set later...

So you could use the Elvis operator (mission?.assignedCards):

<div *ngFor="#item of mission?.assignedCards"
      class="b-progress-bar__item m-progress-bar__item_completed">
  <div class="b-progress-bar__inner">{{item}}</div>
</div>
like image 67
Thierry Templier Avatar answered Dec 07 '25 23:12

Thierry Templier



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!