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

后端 未结 14 1753
北恋
北恋 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:31

    If you're using ngFor for each mat-checkbox, you can do something similar to following in HTML template:

    
        
    
    

    and in TS:

    public personCheckedIndex = -1;
    
    // Called from template when checkbox value changes    
    personCheckboxChange(event: MatCheckboxChange, index: number) {
        // This allows only one checkbox to be checked among each checkbox
        this.personCheckedIndex = event.checked ? index : -1;
    }
    

提交回复
热议问题