How to make default checkbox checked in angular 6?

一个人想着一个人 提交于 2020-01-06 04:45:10

问题


lanuage.component.html

<form method="post" enctype="multipart/form-data">
   <mat-checkbox class="versionstyle" name="languageenabled"[(ngModel)]="languageObj.languageenabled">Enabled</mat-checkbox>
</form>

I want to make checkbox is checked by default in angular6 , i search in google and apply so many solution but it does not work.


回答1:


<mat-checkbox class="example-margin" [(ngModel)]="myModel"/>

OR

<mat-checkbox [checked]="myModel" class="example-margin"/>

Supposed that myModel = true; in component.ts

In your case, try to init this.languageObj.languageenabled = true in component.ts




回答2:


mat-checkbox exposes one @Input() checked: Boolean property. You can do this in your code:

[checked]="languageObj.languageenabled"


来源:https://stackoverflow.com/questions/52094619/how-to-make-default-checkbox-checked-in-angular-6

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!