M
M
Mr. Vazovsky2019-02-05 19:40:41
JavaScript
Mr. Vazovsky, 2019-02-05 19:40:41

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

1 answer(s)
R
Ruslan Lopatin, 2019-02-06
@lorus

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 question

Ask a Question

731 491 924 answers to any question