尝试了我能猜出的每一种语法都无法使其有效!
<!--- THIS WORKS FINE --->
<ion-card *ngFor="#post of posts">
{{post|json}}
</ion-card>
<!--- BLANK PAGE --->
<ion-card *ngFor="#post of posts track by post.id">
{{post|json}}
</ion-card>
<!--- Exception : Cannot read property 'id' of undefined --->
<ion-card *ngFor="#post of posts;trackBy:post.id">
{{post|json}}
</ion-card>
<!--- Exception : Cannot read property 'undefined' of undefined --->
<ion-card *ngFor="#post of posts;trackBy:posts[index].id">
{{post|json}}
</ion-card>
<!--- Blank page no exception raised ! --->
<ion-card *ngFor="#post of posts;#index index;trackBy:posts[index].id">
{{post|json}}
</ion-card>
Run Code Online (Sandbox Code Playgroud)
对我有用的唯一方法是
在控制器类中创建方法
识别(索引,帖子:帖子){return post.id}
和
<ion-card *ngFor="#post of …Run Code Online (Sandbox Code Playgroud) 下图显示了我的表格,其中数据是动态设置的。例如,它可以有 2,3,4 ... 列。
我的 html 代码如下:<thead>包含标题值,并tbody包含可以修改的值。
<table class="table-conf">
<thead>
<tr>
<th *ngFor="let data of jsonText[0]" style="text-align: center;">{{data}}</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let data of jsonText; let i=index">
<ng-container *ngIf="i!=0">
<td class="padding-table" *ngFor="let dt of data; let j=index">
<input style="text-align: center;" [(ngModel)]="jsonText[i][j]">
</td>
</ng-container>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
以下是jsonText我迭代的变量示例:
jsonText Array(6)
0: (2) ["Task", "Hours per Day"]
1: (2) ["Work", 11]
2: (2) ["Eat", 2]
3: (2) ["Commute", 2]
4: (2) ["Watch TV", 2]
5: …Run Code Online (Sandbox Code Playgroud) 请查看相关的矮人
https://plnkr.co/edit/f0BxpinhuqVz8o6IIFaL?p=preview
// stack overflow makes you put code if a plunker is linked but it is too much code to copy paste here it would just look messy so I a am putting this comment instead.
Run Code Online (Sandbox Code Playgroud)
如果运行此命令,然后单击“添加”按钮,则会将新条目添加到数组,但是窗体视图不会反映窗体状态,而是复制第一个条目,最后一个条目消失。
如果有人对我做错了什么有什么想法或指南,我将不胜感激,因为我被困在一个看似简单的任务上。
我试图尽可能遵循官方的Angular Reactive Forms指南来构建此示例。
谢谢