How to validate that at least one checkbox should be selected?

后端 未结 6 1850
遇见更好的自我
遇见更好的自我 2020-12-04 22:20

I want to do validation for checkboxes here without form tag. At least one checkbox should be selected.



        
6条回答
  •  一个人的身影
    2020-12-04 22:34

    Add (ngModelChange)="onChange(officeLIST)" to your checkbox and have below code in your .ts file.

    onChange(items) {
        var found = items.find(function (x) { return x.checked === true; });
        if (found)
          this.isChecked = true;
        else
          this.isChecked = false;
      }
    

    Use isChecked variable any places you want.

提交回复
热议问题