Checkbox angular material checked by default

前端 未结 11 2417
傲寒
傲寒 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:36

    The chosen answer does work however I wanted to make a comment that having 'ngModel' on the html tag causes the checkbox checked to not be set to true.

    This occurs when you are trying to do bind using the checked property. i.e.

    
    

    And then inside your app.component.ts file

    var = true;
    

    will not work.

    TLDR: Remove ngModel if you are setting the checked through the [checked] property

        
    

提交回复
热议问题