rodboc
rodboc

Reputation: 489

*ngIf multidimensional array Angular2

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

Answers (1)

Abdulrahman Alsoghayer
Abdulrahman Alsoghayer

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>

Check this plunk

Please notice that I am using the let-book syntax since the #book syntax is deprecated.

Upvotes: 1

Related Questions