I have pb with angular 2
<div *ngFor="let elm of elements">
<h1> {{elm["0"].value}}</h1>
</div>
how i can acces to value of "elm" if it is an array ? thank you for your help.
If you use "0"
as your key you're implying that you're working on an object
instead of an array
, because arrays
can't have string literals as a key in javascript.
So you want to access it with a number
instead:
<div *ngFor="let elm of elements">
<h1>{{elm[0].value}}</h1>
</div>
If elements
is an array of arrays:
<div *ngFor="let elm of elements">
<h1>{{elm["0"]}}</h1>
</div>
This assumes that the value of elm["0"]
is string or number. If elm["0"]
is an object that has a string/number property called value
then use elm["0"].value
.
If the elm is an array you could access like this:
<div *ngFor="let elm of elements">
<h1> {{elm[0]}}</h1>
</div>
But this also works:
<div *ngFor="let elm of elements">
<h1> {{elm["0"]}}</h1>
</div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.