1
votes

I found in some code of my colleagues detectChanges() and markForCheck(). They are using the default change detection strategy and no NgZones. As far as I know detectChanges and markForCheck is only necessary if you use OnPush strategy or NgZones.

As far as I know these are the use cases for the methods: detectChanges => if you are using runOutsideAngular for example () or somethink like getElementById() and manipulate and element (which should be avoided in angular)

markForCheck => if an object was mutating + OnPush strategy

So is Angulars detectChanges() and markForCheck() relevant for the default change detection strategy?

1

1 Answers

1
votes

Yesn't.

If you're not using ChangeDetectionStrategy.OnPush or ChangeDetectorRef, then both of the methods won't do anything.

You can however, detach the change detector, even with default change detection. in that case you can use detectChanges() to manually check the view.

Read more about change detection here.