In my angular project, I have some booleans that trigger my NgIfs. I want to be able to reset all booleans to false and then set the one relevant boolean to true.
here is an example of my code:
resetBooleans(){
this.mainBoolean = false;
this.secondBoolean = false;
this.thirdBoolean = false;
}
doSecondThing(){
this.resetBooleans();
this.secondBoolean = true;
//do second thing logic
}
Whenever I run this, it resets all the booleans to false and does not then turn this.secondBoolean back to true.
I have tried everything in this post but none of it seems to be working for me.
PS: I'm not interested in using timeouts
Thanks!
update: I added a console.log(this.secondBoolean)
and it came back true, but it is not triggering the NgIf in my HTML... Anyone know why not?
second update:
it isn't the HTML, because this works fine:
doSecondThing(){
this.mainBoolean = false;
this.thirdBoolean = false;
this.secondBoolean = true;
//do second thing logic
}
it's just that I have these boolean resets at the top of every method so I thought it would be cleaner to put all the resets in one method. Once I do though, it stops working.
Final Edit: As is often the case with weird errors like this, it was totally my fault! One of the divs with a different ngIf was not closed so turning that false made everything disappear! Thanks everyone for the help!