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

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

    try this:

    ts:

    import { Component, OnInit, ViewChild} from '@angular/core';

    import { MatSelectionList } from '@angular/material';
    @Component({
        selector : 'app-xxx',
        templateUrl: './xxx.component.html'
    })
    export class xxxComponent implements OnInit {
        public data: Object[] = [ {name : "name 1" }, {name : "name 2" }, {name : "name 3" }, {name : "name 4" } ];
        @ViewChild('element_id') names_list: MatSelectionList;
        ngOnInit() {
            // only if the element is visible on the page, otherwise move this block and execute it until the list is displayed
            setTimeout(()=>{
                this.names_list.selectedOptions._multiple = false;
            },0);
        }
    }
    

    template:

    
        
            {{ d.name }}
        
    
    

提交回复
热议问题