【发布时间】:2017-08-10 07:19:42
【问题描述】:
我在一个小项目中使用 ionic 2 和 angular 2。我希望用户只能从提供的复选框中选择一个复选框。 I added and action listener whenever a checkbox is checked but not sure on what the function should really execute.
<ion-item *ngFor="let category of categories; let i = index">
<ion-label [innerHTML]="category.name"></ion-label>
<ion-checkbox color="royal" checked="category.value" (click)="Selection(i,categories);"></ion-checkbox>
</ion-item>
这是 JSON 对象的示例
categories = [
{
name: 'Car Keys',
value: 'false'
},
{
name: 'Phone',
value: 'false'
},
{
name: 'ID/Drivers License',
value: 'false'
},
{ name: 'Wallet',
value: 'false'
},
{ name: 'Other',
value: 'false'
}]
我正在将类别索引传递给函数,但不确定还要检查什么。任何帮助将不胜感激。
【问题讨论】:
-
为什么不用单选按钮来代替?
-
用示例 json 更新帖子,你能创建一个 plunker 吗?
-
你为什么写
<ion-label [innerHTML]="category.name"></ion-label>而不是<ion-label>{{category.name}}></ion-label>
标签: javascript angularjs angular checkbox ionic2