Why do we need `ngDoCheck`

Discussão em 'Angular' iniciado por Max Koretskyi, Março 20, 2025.

  1. I can't seem to figure out why I need ngDoCheck lifecycle hook other than for simple notification, particularly how writing code inside of it makes a difference as regard to change detection. Most of the examples I've found show useless examples, like this one, with a bunch of logging functionality.

    Also, in the generated classes I don't see it being used for something else other than simple notification:

    conmponent/wrapper.ngfactory.js

    Wrapper_AppComponent.prototype.ngDoCheck = function(view,el,throwOnChange) {
    var self = this;
    var changed = self._changed;
    self._changed = false;
    if (!throwOnChange) {
    if (changed) {
    jit_setBindingDebugInfoForChanges1(view.renderer,el,self._changes);
    self._changes = {};
    }
    self.context.ngDoCheck(); <----------- this calls ngDoCheck on the component
    but the result is not used
    anywhere and no params are passed
    }
    return changed;
    };

    Continue reading...

Compartilhe esta Página