I have an HttpClient
service which is updating the data at backend. During the processing at backend, I' am displaying a loading state by doing this.isLoading = true
, and after the successfully processing, I' am removing that loading state in subscribe()
by using this.isLoading = false;
.
Now I changed my code to use ChangeDetectionStrategy.OnPush
and the loading state is not vanishing anymore. I know the change detection in ChangeDetectionStrategy.OnPush
occurs when an input
property is changed or when an object reference is changed during an event on component etc.
In my case, do I have to manually call ChangeDetectorRef.detectChanges()
to trigger change detection or am I missing something?
Edit
Just to clear, I' am using this.isLoading
to show/hide loading state by adding/removing class on an HTML element accordingly. For example,
<div [class.processing]="isLoading"></div>
ChangeDetection.OnPush()
o you can useasync
pipe. – Planetesimal@Input
, it maintains a local variableisLoading
(boolean) to show/hide loading state. I thinkasync
won't work with boolean? I have updated the question, please view again. – Kiruna[class.processing]
to<div [ngClass]="{'processing': isLoading}"></div>
– Planetesimalsubscribe()
. – Kiruna