Reputation: 489
I have created an array to call it from the template in Angular 2
books: any[] = [{
name: "The Name book",
chapter: [{
name: 'Alpha',
pages: '180'
}, {
name: 'Beta',
pages: '100'
}]
}]
So, in the template, I would like to call it like this
<li *ngFor="#book of books" >
{{book.chapter.name}}
</li>
But it doesn't work, any help please?
Upvotes: 1
Views: 1996
Reputation: 16540
The chapter
property is an array, so you have to pass it to ngFor
also.
<template ngFor [ngForOf]="books" let-book>
<li *ngFor="let chapter of book.chapter">
{{chapter.name}}
</li>
</template>
Please notice that I am using the let-book
syntax since the #book
syntax is deprecated.
Upvotes: 1