Checkbox angular material checked by default

前端 未结 10 1692
猫巷女王i
猫巷女王i 2021-02-11 19:47

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?



        
10条回答
  •  北恋
    北恋 (楼主)
    2021-02-11 20:34

    If you are using Reactive form you can set it to default like this:

    In the form model, set the value to false. So if it's checked its value will be true else false

    let form = this.formBuilder.group({
        is_known: [false]
    })
    

    //In HTML

     Known
    

提交回复
热议问题