0

So I have this checkbox, I have binded ngModel to it and based on the ngModel it properly sets the checkbox as checked or unchecked.

The problem is, if I change the checkbox, I check for some conditions and based on some that condition I make the ngModel binded to it false again, so technically it should go back to unchecked state if it was checked and the condition satisfied, but it's not. Although my ngModel shows a value of false.

Even tried with the [checked] attribute, but it's also not working.

Any inputs are highly appreciated

<input type="checkbox" [(ngModel)]="isChecked" [checked]="isChecked" (ngModelChange)="onChange('statusPush',$event)">

in Component

if(someCondition) {
this.isChecked = false
}
3
  • I don't know what you are asking. But I'm guessing this might help you --> stackoverflow.com/questions/54450254/… if what described there is what you intended to do Commented Jan 30, 2019 at 22:35
  • Chill bro, it's been over a year! Commented Jan 31, 2019 at 7:08
  • I'm just trying to help to solve your cold case. I ain't no bro, either. LOL! Commented Jan 31, 2019 at 13:48

1 Answer 1

0

This code worked for me, just add a time out function before making the value of isChecked true or false in your onChange function

if(someCondition) {
  setTimeout(()=>{
    this.isChecked = false
  });
}

Hope this helps.

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

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.