问题
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