-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set default state of a checkbox #405
Comments
have you tried |
I hadn't tried it but I tried it just then and it didn't work:( |
here's a plnkr where I have it working |
Well there you go. I must have been doing something wrong. I'll try again. Thanks for taking the time to set up the demo. I really appreciate it. |
Hello, how could I make sure all checked checkboxes (isAvailable = true) are cleared at the click of the button? |
julioaze , u need to create different variable for each check box. It will work . Example; .ts: <input type="checkbox" [checked]="isUser" value="isUser" (change)="isUser= $event.target.checked" formControlName="aaa"> |
In Angular 2+, If you're using template forms and/or ngModel then you can set default checkbox values right in the model you declare. When declaring the boolean values do something like this:
when you load up the form with undefined values -they will default to what you set in the model |
Hello, Sir |
<ng-container *ngFor="let opt of option_set_ids"> |
This seems like a really stupid question but I just can't find the answer anywhere.
I want to set the initial state of a checkbox based the initial state of the data object.
Eg the data object may have an attribute "isAvailable" so I want to set the checkbox to match the value of isAvailable.
The problem I am having is that to set the initial state of a check box to checked you add the "checked" attribute to the form control.
(This seems silly as it would seem better to have used checked="true" as you can read the value of the checkbox by reading its "checked" value. Anyway that's not the way it is.)
So it looks like I would have to do an NgIf.
I'm sure there must be an easier way but I just can't find it.
The text was updated successfully, but these errors were encountered: