Angular mat-selection-list, How to make single checkbox select similar to radio button?

后端 未结 14 1703
北恋
北恋 2021-02-18 21:22

How to make make single checkbox select from mat-selection-list. Similar to radio button which accepts one value from group of values.

14条回答
  •  逝去的感伤
    2021-02-18 21:36

    you can use 'mat-checkbox' instead of 'mat-selection-list' and play with click event like this:

    HTML

     

    TS

    @ViewChildren('checkBoxes') checkBoxes: QueryList;
    
     changeCheckBox() {
        this.checkBoxes.filter((checkbox: MatCheckbox) =>
          checkbox.checked === true
        )[0].checked = false;
      }
    

    remember that all check boxes default value is unchecked.

提交回复
热议问题