【发布时间】:2019-09-22 17:41:58
【问题描述】:
我试图在 ionic 4 应用程序中仅启用一个复选框,我已经开始了一些代码,但现在我被卡住了,我想我必须使用 ngModel..
我想在检查时将reponse.checked 更改为正确,然后将所有其他检查的数组设为 false...
html
<ion-card>
<ion-card-title>
Question 1
</ion-card-title>
<ion-card-subtitle>
Test
</ion-card-subtitle>
<ion-list>
<ion-item *ngFor='let rep of reponse'>
<ion-label>{{rep.name}}</ion-label>
<ion-checkbox
[(ngModel)]="isChecked"
color="primary"
slot="start"></ion-checkbox>
</ion-item>
</ion-list>
</ion-card>
.ts
export class SurveyPage implements OnInit {
reponse = [
{
name: 'test',
checked: false
},
{
name: 'test2',
checked: false
},
];
constructor() { }
ngOnInit() {
}
isChecked( {
});
}
【问题讨论】:
-
这是单选按钮的默认行为,那你为什么要使用复选框呢?