Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 在ionic4应用程序中仅启用一个复选框_Angular_Ionic4 - Fatal编程技术网

Angular 在ionic4应用程序中仅启用一个复选框

Angular 在ionic4应用程序中仅启用一个复选框,angular,ionic4,Angular,Ionic4,我试图在ionic 4应用程序中只启用一个复选框,我已经开始编写一些代码,但现在我卡住了,我想我必须使用ngModel。。 我想在选中时将response.checked更改为右侧,然后将false设置为数组中所有其他选中项 html <ion-card> <ion-card-title> Question 1 </ion-card-title> <ion-card-subtitle> T

我试图在ionic 4应用程序中只启用一个复选框,我已经开始编写一些代码,但现在我卡住了,我想我必须使用
ngModel
。。 我想在选中时将
response.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>

您可以使用
ngModelChange
重置其他选定项


{{rep.name}
更新的检查表方法

updatedCheckList(项目索引:编号){
this.response.forEach((rep,index)=>{
如果(itemIndex!==索引){
rep.checked=false
}
})
}

演示您可以使用
ngModelChange
重置其他选定项


{{rep.name}
更新的检查表方法

updatedCheckList(项目索引:编号){
this.response.forEach((rep,index)=>{
如果(itemIndex!==索引){
rep.checked=false
}
})
}

演示这是radiobutton的默认行为,为什么要使用复选框?这是radiobutton的默认行为,为什么要使用复选框?@Yann92很乐意帮助您为什么不使用radio而不是checkbox?我会的,我不知道它的存在。但好东西,我已经明白了它的用途ngModelChange@Yann92很高兴帮助你为什么不用收音机代替复选框?我会的,我不知道它的存在。但好事情是,我已经明白了改变的用途
export class SurveyPage implements OnInit {

reponse = [
  {
    name: 'test',
    checked: false
  },
  {
    name: 'test2',
    checked: false
  },
];

  constructor() { }

  ngOnInit() {

  }

isChecked( {

});

}