当尝试在数组中迭代数据时,如何在HTML中正确处理ngFor?

当尝试在数组中迭代数据时,如何在HTML中正确处理ngFor?,html,angular,angular9,Html,Angular,Angular9,问题是,我尝试迭代数组中的数据,最后显示出来。但问题是,当遍历它时,它会显示重复的标题 component.html 您应该将标题行置于迭代之外: <table class="table"> <tr> <th>Column 1</th> <th>Column 2</th>

问题是,我尝试迭代数组中的数据,最后显示出来。但问题是,当遍历它时,它会显示重复的标题

component.html



您应该将标题行置于迭代之外:

        <table class="table">
            <tr>
                <th>Column 1</th>
                <th>Column 2</th>
                <th>Column 3</th>
                <th>Column 4</th>
                <th>Column 5</th>
                <th>Column 6</th>
                <th></th>
            </tr>
            <ng-container *ngFor="let group of groups">
                <tr *ngFor="let types of group.Team">
                    <td *ngIf="types .ID">{{types.ID.firstColumn}}</td>
                    <td *ngIf="types .ID">{{types.ID.secondColumn}}</td>
                    <td *ngIf="types .ID">{{types.ID.thirdColumn}}</td>
                    <td *ngIf="types .ID">{{types.ID.fourthColumn}}</td>
                    <td *ngIf="types .ID">{{types.ID.fifthColumn}}</td>
                    <td *ngIf="types .ID">{{types.ID.sevenColumn}}</td>
                </tr>
            </ng-container>
        </table>

第1栏
第2栏
第3栏
第4栏
第5栏
第6栏
{{types.ID.firstColumn}
{{types.ID.secondColumn}
{{types.ID.thirdColumn}
{{types.ID.fourthColumn}
{{types.ID.fifthColumn}
{{types.ID.sevenColumn}
        <table class="table">
            <tr>
                <th>Column 1</th>
                <th>Column 2</th>
                <th>Column 3</th>
                <th>Column 4</th>
                <th>Column 5</th>
                <th>Column 6</th>
                <th></th>
            </tr>
            <ng-container *ngFor="let group of groups">
                <tr *ngFor="let types of group.Team">
                    <td *ngIf="types .ID">{{types.ID.firstColumn}}</td>
                    <td *ngIf="types .ID">{{types.ID.secondColumn}}</td>
                    <td *ngIf="types .ID">{{types.ID.thirdColumn}}</td>
                    <td *ngIf="types .ID">{{types.ID.fourthColumn}}</td>
                    <td *ngIf="types .ID">{{types.ID.fifthColumn}}</td>
                    <td *ngIf="types .ID">{{types.ID.sevenColumn}}</td>
                </tr>
            </ng-container>
        </table>