Say there's two components: CompP, CompC. CompP is the parent component of CompP and it sets ChangeDetectionStrategy
as OnPush
. Under this setup, if some changes happen to a property of CompC, which only affects its view. At first, I expected it would update its(CompC) view automatically but it didn't happen. If I'm correct, it's because CompP is taking OnPush
setup. It stops the change detection which occured by CompC and flew down from the root. So here's my question: if I want that change to be updated on the view at CompC, should I use detectChanges
method of changeDetector
manually? Apparently, it works but I wonder if there's other way to make it work other than calling detectChanges
or markForCheck
manually. Any insight would be appreciated!
Asked
Active
Viewed 319 times
1

DongBin Kim
- 1,799
- 5
- 23
- 43
-
1this might help https://stackoverflow.com/questions/35386822/changedetectionstrategy-onpush-and-observable-subscribe-in-angular-2 – Jayakrishnan Jan 12 '18 at 10:18
-
That depends on what change occured. If it's something outside the scope of Angular, it won't be updated unless you call `changeDetector` manually yes. However, if you are using `Inputs` / `Outputs` between CompP and CompC, the changes will be updated as it is within the scope of Angular. – Alex Beugnet Jan 12 '18 at 14:31
-
@JayakrishnanGounder Thanks man! That helped me alot! – DongBin Kim Jan 15 '18 at 05:31
-
@AlexBeugnet Yeah I understand but the problem I'm facing is that the case when the property of CompC changes without getting affected by CompP by `Input` or anything. Since all the `changedetection`s are prevented by CompP, CompC's view won't get updated unless it triggers `changeDetector` by itself. Am I correct? – DongBin Kim Jan 15 '18 at 05:34