Answer the question
In order to leave comments, you need to log in
How to use ChangeDetectionStrategy.OnPush if there are no inputs in the components?
Good day, friends!
There is a component A with two children, let's say B and C. All detectionStrategy OnPush, and they all work through one common service. Component B has a button that changes the value of some property in the service, and this property in the service should change component C. Without onPush, everything works fine, after setting it - no. I would be grateful if anyone can help me fix this problem....)
Answer the question
In order to leave comments, you need to log in
The service should have not just a property, but an Observable that publishes changes in its value. Then component C will be able to subscribe to these changes. And in the subscriber, call ChangeDetectionRef.detectChanges() after they have been applied.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question