1

I want to render data from array into HTML table. Here's my model:

export class Section {
    public id :number;
    public name: string;
    constructor(id: number, theName: string) {
        this.id = id;
        this.name = theName;
    }
}

I import it and fill it in the component:

import { Section } from "../models/registerSection.model";

Array declaration:

sectionList: Array<Section>;

Array is filled in constructor:

    this.sectionList = [new Section(1, "A"),
        new Section(2, "B*"),
        new Section(3, "C"),
        new Section(4, "D")];

This is how I'm trying to render data in template:

        <ng-container *ngFor='let data of Section'>
            <tr>
                <td colspan="7">{{data.name}}</td>
            </tr>
        </ng-container>

But the table is empty. In DOM, I see the following:

<!--template bindings={
  "ng-reflect-ng-for-of": null
}-->

What am I doing wrong? In debugging I can see that array contains data.

1 Answer 1

2

It should be:

<ng-container *ngFor='let data of sectionList'>

Right now, you are trying to iterate through Section model, not sectionList which is instance of that model.

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.