【发布时间】:2019-12-23 13:02:20
【问题描述】:
考虑有这个简单的表格:
<nz-table #table [nzData]="users">
<thead>
<tr>
<th>Id</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let item of table.data">
<td>{{item.id}}</td>
<td>{{item.firstName}}</td>
<td>{{item.lastName}}</td>
</tr>
</tbody>
</nz-table>
还有这个 .ts 文件:
import { Component } from '@angular/core';
interface User {
firstName: string;
latName: string;
}
@Component({
selector: 'app-list',
templateUrl: './list.component.html',
styleUrls: ['./list.component.scss']
})
export class ListComponent {
users: User[] = [];
}
如何在 html 模板中为 firstName 和 lastName 字段获取智能感知?我的 IDE 说 item 变量的类型为 any,它应该是 User 类型。
为什么还需要模板引用?为什么我们不能只使用<tr *ngFor="let item of users">(除了分页不起作用的事实)?
【问题讨论】:
-
您使用的是哪个 IDE?
-
我正在使用 Intellij
标签: html angular datatable ng-zorro-antd