Sachin
Sachin

Reputation: 2765

how to prevent change detection when an event fired while using 'changeDetection: ChangeDetectionStrategy.OnPush'?

I have a getter property with some complex calculations and inorder to prevent unnecessary changeDetections I changed to ChangeDetectionStrategy to OnPush.

Even After using ChangeDetectionStrategy.OnPush the getter gets executed on every possible events fired in the view like button clicks.

And this is causing some serious performance issues in my app. Is there any way to disable the changedetection and trigger it only when needed ? Thanks.

Upvotes: 2

Views: 1205

Answers (1)

Tinki
Tinki

Reputation: 1526

Your question is very vague, as you don't provide any code sample. For this reason it is really difficult to find a reason, why onPushstrategy doesn't work for your case. I would advice comparing your code against examples of common pitfalls mentioned in this article.

You might also consider implementing onChanges() lifecycle hook and manually define cases, for which change computations should take a place.

Upvotes: 2

Related Questions