Angular2, disable button if no checkbox selected

前端 未结 4 1970
悲哀的现实
悲哀的现实 2020-12-15 05:11

I have multiple checkboxes and a button that has to be enabled only if at least one checkbox is selected

VALUE1


        
4条回答
  •  心在旅途
    2020-12-15 05:47

    One way is to use ngModel on each checkbox, then control the button's disabled property via a method that examines each checkbox model state:

    @Component({
      template: `
        
        

    ` }) class App { checkboxes = [{label: 'one'},{label: 'two'}]; constructor() {} buttonState() { return !this.checkboxes.some(_ => _.state); } }

    Plunker

提交回复
热议问题