如何绑定到Ionic 2中的ngFor循环中的项目? [英] How to bind to an item in an ngFor loop in Ionic 2?
本文介绍了如何绑定到Ionic 2中的ngFor循环中的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的模板中,我有
<ion-card *ngFor="let item of items">
<p>{{ item.timespan }}</p>
</ion-card>
但是,我想在其他地方绑定它,而不是在循环中显示值。模板,在ngFor循环之外,如
However, instead of displaying the value inside the loop, I want to bind to it from somewhere else in the template, outside the ngFor loop, like
<h1>{{ timespan }}</h1>
<ion-card *ngFor="let item of items" [timespan]="item.timespan">
…
</ion-card>
但我认为我不能使用[timespan],因为它不是ion-的输入属性卡..
But I assume I can’t use [timespan] since it is not an input property of ion-card..
所以有人知道我怎么能实现这个绑定吗?
So does anyone know how else I can implement this binding?
任何帮助都非常感谢。
Any help greatly appreciated.
推荐答案
您可以使用 template
代替<$ c来完成此操作$ c> * ngFor 来处理循环:
You can accomplish this by using template
instead of *ngFor
to handle the loop:
<template ngFor let-item [ngForOf]="items">
<h1>{{item.timespan}}</h1>
<ion-card>
…
</ion-card>
</template>
这是 Plunker 。
这篇关于如何绑定到Ionic 2中的ngFor循环中的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文