0

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.

3
  • Just set the ngModel's value to true for the one you want to be default Commented Aug 30, 2018 at 10:21
  • No, more like this.languageObj.languageenabled = true for example. (And also, your HTML shouldn't have the this bit in it) Commented Aug 30, 2018 at 10:25
  • Then it appears your languageenabled property has been typed as a string, which is an issue somewhere within your code. Commented Aug 30, 2018 at 10:41

3 Answers 3

4
<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

Sign up to request clarification or add additional context in comments.

Comments

1

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

[checked]="languageObj.languageenabled"

2 Comments

Thanks Jai, but it gives error like argument type 'boolean' is not assignable to parameter of type 'string : blob'
@AmishaRana okay got this and glad you got your issue resolved.
0

For Checked-checkbox

<form method="post" enctype="multipart/form-data">
    <mat-checkbox 
      [checked]="true">Checked
    </mat-checkbox>
</form>

For Unchecked-checkbox

<form method="post" enctype="multipart/form-data">
    <mat-checkbox 
      [checked]="false">Uncheked
    </mat-checkbox>
</form>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.