0

I want to bind field value in current object and switch checkbox depend on it value.

My checkbox:

<label class="checkbox-inline checbox-switch switch-success">
<input
  #livingRoom
  type="checkbox"
  name="livingRoom"
  id="livingRoom"
  [checked]="showDefaultTypeRoom.isExistLivingRoom"
/>
<span></span>
</label>

I change showDefaultTypeRoom object and isExistLivingRoom but my checkbox is not switching depend on isExistLivingRoom value.

How fix it?

2 Answers 2

1

Use:

<input type="checkbox" [(ngModel)]="test.value"/>

And in TS:

public test = {value: true};

try here: https://stackblitz.com/angular/demklkjdbqq

(or use reactive form style)

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

1 Comment

see here: https://blog.thoughtram.io/angular/2016/10/13/two-way-data-binding-in-angular-2.html#understanding-ngmodel
0

You should use 2 way binding :

[(ngModel)]="showDefaultTypeRoom.isExistLivingRoom"

instead of :

[checked]="showDefaultTypeRoom.isExistLivingRoom"

4 Comments

I think if you wanna do it that way you should split the 2-way binding: [checked]="showDefaultTypeRoom.isExistLivingRoom" (checkedChange)="setTheValue($event)"
@Guntram , Sorry for typo , I was meant to say ngModel with 2 way data binding
Yeah, I know, typing fast to answer quickly :)
@Guntram , Exactly :)

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.