代码之家  ›  专栏  ›  技术社区  ›  Fish-Guts

仅HTML中显示的第一个元素

  •  1
  • Fish-Guts  · 技术社区  · 6 年前

    我正在组件的NgOnInit函数中加载一个“Client”数组。在这个调用之后,我想初始化一个类型为“TimeSheet”的数组,它将“Client”作为元素。我是这样做的:

    init(clients : Client[]) {
        let i = 0;
        this.timeSheets = new Array(clients.length);
        for(let client of clients) {
            console.log("client firstname" + client.firstName);
            this.timeSheets[i] = new TimeSheet();
            this.timeSheets[i].client = client;
            console.log("client last name in timesheet: " + 
            this.timeSheets[i].client.lastName);
            i++;
        }
    }    
    

    浏览器控制台显示客户端的正确值:

    client firstname Hans
    client last name in timesheet: Müller
    client firstname John
    client last name in timesheet: Smith
    client firstname Marie
    client last name in timesheet: Curie
    

    但是,在我的HTML模板中,只显示第一个元素。这是我放在前端的部分:

    <tr *ngFor="let timeSheet of timeSheets ;trackBy: trackId">
        <td>{{timeSheet.client.lastName}}</td>
        <td>{{timesheet.client.firstName}}</td>
        <td><input type="text" (change)="calculate($index)"></td>
        <td><input type="text"></td>
    </tr>
    

    ERROR TypeError: Cannot read property 'client' of undefined
    

    它看起来是这样的: enter image description here

    另外,按钮标签和表头也不见了,所以我推测代码中有一些错误。请帮我找到它。

    1 回复  |  直到 6 年前
        1
  •  3
  •   Mathias    6 年前


    应该是

    便笺大小写

    推荐文章