Reputation: 45
I have the following *ngFor loop and inside the loop I've got another div where I have applied a directive which expects an object parameter :
<div class="container" *ngFor="let item of items">
<div [directiveName]="{testParamKey: item.name}"></div>
</div>
It gives me an error : "Cannot read property 'name' of undefined". I wonder how do i pass this parameter using the item from the for loop ?
Thanks in advance.
Upvotes: 0
Views: 195
Reputation: 41407
use the optional operator. ?
<div [directiveName]="{testParamKey: item?.name}"></div>
Upvotes: 2