【问题标题】:Ng Zorro table - Items in table have type `any`(bad Intellisense)Ng Zorro 表 - 表中的项目类型为 `any`(错误的 Intellisense)
【发布时间】: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 模板中为 firstNamelastName 字段获取智能感知?我的 IDE 说 item 变量的类型为 any,它应该是 User 类型。

为什么还需要模板引用?为什么我们不能只使用&lt;tr *ngFor="let item of users"&gt;(除了分页不起作用的事实)?

【问题讨论】:

  • 您使用的是哪个 IDE?
  • 我正在使用 Intellij

标签: html angular datatable ng-zorro-antd


【解决方案1】:

nzTemplateMode设置为false,然后就不需要像[nzData]="users"这样将用户绑定到nzData。然后就可以直接使用&lt;tr *ngFor="let item of users"&gt;

<nz-table [nzTemplateMode]="false" >
    <thead>
        <tr>
            <th>Id</th>
            <th>First Name</th>
            <th>Last Name</th>
        </tr>
    </thead>
    <tbody>
        <tr *ngFor="let item of users">
            <td>{{item.id}}</td>
            <td>{{item.firstName}}</td>
            <td>{{item.lastName}}</td>
        </tr>
    </tbody>
</nz-table>

【讨论】:

  • 出现同样的问题:表格将所有数据呈现在一页中。分页在那里,但它不起作用(并且它不能工作,因为所有数据都在一页中)
  • 这是example
猜你喜欢
  • 2020-03-01
  • 2021-11-22
  • 1970-01-01
  • 2023-03-06
  • 1970-01-01
  • 2019-03-27
  • 2022-10-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多