angular icon indicating copy to clipboard operation
angular copied to clipboard

ngDoCheck hook has a bit misleading documentation

Open lukasmatta opened this issue 3 years ago • 1 comments

Describe the problem that you experienced

Hello,

in my opinion the documentation regarding the DoCheck hook is a bit misleading: A lifecycle hook that invokes a custom change-detection function for a directive, in addition to the check performed by the default change-detector.

Text in bold implies that the default check was performed (for the component from which the hook is called), when in fact it doesn't need to be the case. If we have a component with the OnPush change detection strategy, its ngDoCheck hook is called from its parent, despite the fact that the default check was not performed on the component.

The following article sums up why ngDoCheck called =/= change detection performed (it's from 2017, I think that many people fell in the trap of believing that ngDoCheck called = change detection performed): https://medium.com/angular-in-depth/if-you-think-ngdocheck-means-your-component-is-being-checked-read-this-article-36ce63a3f3e5

Enter the URL of the topic with the problem

No response

Describe what you were looking for in the documentation

No response

Describe the actions that led you to experience the problem

No response

Describe what you want to experience that would fix the problem

No response

Add a screenshot if that helps illustrate the problem

No response

If this problem caused an exception or error, please paste it here

No response

If the problem is browser-specific, please specify the device, OS, browser, and version

No response

Provide any additional information here in as much as detail as you can

No response

lukasmatta avatar Nov 20 '22 19:11 lukasmatta

@lukasmatta Also related to the formulations here: image

If we have a component with the OnPush change detection strategy, its ngDoCheck hook is called from its parent, despite the fact that the default check was not performed on the component.

It's the most crucial part you've mentioned.

mlc-mlapis avatar Nov 20 '22 19:11 mlc-mlapis

Yeh, we could use more precise wording. How about https://github.com/angular/angular/pull/48209#discussion_r1042299939 ?

pkozlowski-opensource avatar Dec 07 '22 14:12 pkozlowski-opensource