Angular *ngFor on ng模板不输出任何角度2
不知道为什么我的*ngFor循环没有打印任何内容。我在html文件中有以下代码:Angular *ngFor on ng模板不输出任何角度2,angular,Angular,不知道为什么我的*ngFor循环没有打印任何内容。我在html文件中有以下代码: <table class="table table-hover"> <thead> <tr> <th>Name</th> <th>Email</th> <th>Company</th> &l
<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>
当我运行这段代码时,我得到零输出。更奇怪的是,当我使用调试工具选择元素时,我看到:
看起来它正确地识别了我的对象,但没有输出任何东西。我想你想要的是
或
获取索引:
谢谢!无论是谁设计了ng模板的语法,都需要在斯塔克诺被烧掉,不知道你在抱怨什么。这是正常的角度模板语法。他们引入了
,以便能够在
元素上使用更简洁、更常见的*xxx
语法。他们对ng容器做出了明智的决定。这种语法非常不直观。不,不是;-)ngFor
使用选择器添加指令ngFor
,让xb
在模板[ngForOf]=“tempData”
中提供模板实例化的上下文,将tempData
分配给ngFor
指令。这是非常常见的Angular2模板语法。你应该适应它。例如,如果您想使用ngForTemplate
或ngTemplateOutlet
,或者如果您构建自定义结构指令,如*ngIf
和*ngFor
。回答不错,解决了我的问题。ng模板语法毫无意义,并且与anguaar中的任何其他语法完全不一致-让xb生成一个名为xb的变量?世界跆拳道联盟?
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() {}
}