相关疑难解决方法(0)

如何在ngFor angular 2中使用track

尝试了我能猜出的每一种语法都无法使其有效!

<!--- 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)

对我有用的唯一方法是

  1. 在控制器类中创建方法

    识别(索引,帖子:帖子){return post.id}

<ion-card *ngFor="#post of …
Run Code Online (Sandbox Code Playgroud)

angularjs-track-by ngfor angular

46
推荐指数
3
解决办法
8万
查看次数

在angular2中调用ngFor中的函数

您好我正在使用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)

angular

14
推荐指数
4
解决办法
4万
查看次数

标签 统计

angular ×2

angularjs-track-by ×1

ngfor ×1