尝试了我能猜出的每一种语法都无法使其有效!
<!--- 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) 您好我正在使用Angular2并且想要获取服务器并为我在ngFor中获取的每个ID获取一些值.
<div *ngFor="let item in items">
<span> here call a function that do something with 'item' and return something new <span>
</div>
Run Code Online (Sandbox Code Playgroud)