考虑有这个简单的表:
<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
变量具有 typeany
并且它应该是 type User
。
为什么仍然需要模板参考?为什么我们不能只使用<tr *ngFor="let item of users">
(除了分页不起作用的事实)?