1

In a regular HTML file we can do as in html to have a privilege to check the checkbox by clicking anywhere on label, even by setting the checkbox input display to none

 <label for="check">
   <input id="check"  type="checkbox">
 </label>

Why same is not working in Angular? I'm interested how I can do same in Angular 5+.

2
  • Its same for the angular 5 too, did you tried? Commented Oct 31, 2018 at 16:31
  • Yes i tried but it didn't work. Actually I want to apply some styling when it is checked and don't want to use .ts for that but it didn't work Commented Oct 31, 2018 at 17:00

1 Answer 1

3

It works in Angular as well.

Sample code

<label for="check"> Click here
   <input id="check" [(ngModel)]="hello" [hidden]="true"  type="checkbox">
 </label>

Demo is here - https://stackblitz.com/edit/angular-6ncjng

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

4 Comments

I don't need a function, the only thing that I need is to make it checked so to trigger CSS style.
Yeah, the example given is not using any function.
In my case it is not working, I make [hidden]="false" and when I click on area of label, it doesn't work. Do you have any idea why it is not working?
Need to check what you have done exactly, it will be easier if you can create a sample in stackblitz.

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.