Ngif doesnt update the view of page after calling through Events


#1

Hello folks,

I have a page and provider, when I set the boolean variable through provider using Events method, Ngif doesnt work, I have a function that sets the ngif variable to true, However when I call this function using button, It works…
But when I call the function using Events It is not working.

Is there anyone know why it is happening ?


#2

Ionic emitting an event gets registered by a subscription if you’re subscribing to Events, but that isn’t something Angular listens to for change detection. You might want to read up on exactly what triggers change detection. It’s very specific things, like a button click (which you already noticed).

Solution: inside your subscription, after you update the value of the variable, call ChangeDetectorRef.detectChanges(). You’;ll need to inject ChangeDetectorRef in your constructor. That will manually fire Angular’s change detection.


Variable won't get updated in view
#3

Yes, you are right :slight_smile: Thanks for answer, it is detecting now.