0

I tried to display checkbox inside angular UI

<mat-checkbox [(ngModel)] = "item.role" [checked]="false"> 
  <label>IT Admin</label> 
</mat-checkbox>

I have attached image below and if I tried to create style for mat-checkbox the style is applied including label.enter image description here

2
  • Hi, change the binding [checked]="false" to [checked]="item.role", I don't understand what is your problem. Commented Aug 29, 2019 at 12:21
  • When the check box is not clicked the box is not visible Commented Aug 29, 2019 at 13:44

1 Answer 1

1

The style is applied to the label because the label is inside of the mat-checkbox tag. Try separating them and using a form group if you can.

<div class="form-group"> <label for="role">IT Admin</label> <mat-checkbox id="role" [(ngModel)]="item.role" [checked]="item.role"></mat-checkbox> </div>

This is under the assumption that you are using forms.

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

5 Comments

Hi Nick, I don't have concern on label, I want the checkbox to be displayed even if it is not clicked
Oh, I see. I misunderstood the question. have you tried adding a class with a border to the mat-checkbox like <mat-checkbox class="something" ...>
Thank You I am able to style the check box alone now
May be worth noting that MatCheckboxModule should be imported into app.module.ts , later versions of Angular may not call out error if it's missing.
@karansys: plz provide your solution.

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.