1

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.