Checkbox angular material checked by default

前端 未结 11 2407
傲寒
傲寒 2021-02-11 19:37

I am trying to use an Angular Material checkbox, and set it by default as checked, but it is displayed as non-checked, what is wrong?



        
11条回答
  •  死守一世寂寞
    2021-02-11 20:27

    // in component.ts
    checked: boolean = true;
    indeterminate:boolean = false;
    disabled:boolean = false;
    label:string;
    
    onCheck() {
        this.label = this.checked?'ON':'OFF';
    }
    
    // in component.html`enter code here`
    
                        {{label}}
                      
    

    The above code should work fine. Mat checkbox allows you to make it checked/unchecked, disabled, set indeterminate state, do some operation onChange of the state etc. Refer API for more details.

提交回复
热议问题