不知道为什么我的*ngFor循环什么也没打印出来.我在html文件中有以下代码:

<table class="table table-hover">
    <thead>
        <tr>
            <th>Name</th>
            <th>Email</th>
            <th>Company</th>
            <th>Status</th>
        </tr>
    </thead>
    <tbody>
        <!-- NGFOR ATTEMPTED HERE -- no content printed -->
        <ng-template *ngFor="let xb of tempData">
            <tr data-toggle="collapse" data-target="#demo1" class="accordion-toggle">
                <td>{{ xb.name }}</td>
                <td>{{ xb.email }}</td>
                <td>{{ xb.company }}</td>
                <td>{{ xb.status }}</td>
            </tr>
            <!-- other content -->
        </ng-template>
    </tbody>
</table>

然后,在我的简单组件中,我有以下内容:

import { Component }        from '@angular/core';

@Component({
    selector: 'my-profile-exhibitors',
    templateUrl: './profile-exhibitors.component.html',
    styleUrls: ['./profile-exhibitors.component.scss']
})
export class ProfileExhibitorsComponent {
    public tempData: any = [
        {
            'name': 'name1',
            'email': 'email1@gmail',
            'company': 'company',
            'status': 'Complete'
        },
        {
            'name': 'name2',
            'email': 'email2@gmail',
            'company': 'company',
            'status': 'Incomplete'
        }
    ];
    constructor() {}
}

当我运行这段代码时,我得到零输出.更奇怪的是,当我使用调试工具 Select 元素时,我看到:

enter image description here

看起来它正确识别了我的对象,但没有输出任何内容.

推荐答案

我想你想要的是

<ng-container *ngF或="let xb of tempData">

<ng-template ngF或 let-xb [ngF或Of]="tempData">

Angular相关问答推荐

将Angular Metal的芯片组件集成到我的表单中时出错

根据Angular中的构建来卸载独立组件

cat Owl carousel 位置下一个和上一个图片

如何在Angular模块中的forRoot中注入配置

RXJS运算符用于combineLatest,不含空值

更改图表上的光标以进行zoom

Change上的Angular 自定义控件无法正常工作

MAT-复选框更改事件未在onSubscriberCheck函数中返回选中的值

崩溃Angular项目Docker容器

当信号的值发生变化时,模板不会更新

无法在单个元素上多次监听同一个事件

Angular 按钮指令错误地附加子元素

Angular:为什么在我的自定义 ErrorHandler 中订阅主题不触发?

Angular 项目构建仅在 GitHub Actions 上失败

Observable .do() 运算符 (rxjs) 的用例

在 Angular material表上调用 renderRows()

取消订阅服务中的http observable

找不到模块angular2/core

如何在 Angular cli 项目中包含来自 node_modules 的assets

如何在 Angular 中使用带有 SASS 的 Bootstrap 4