R
R
Roman Rakzin2022-01-25 17:28:25
Angular
Roman Rakzin, 2022-01-25 17:28:25

ngOnInit does not work, although the element has been rendered. What can be wrong?

Angular hooks work for all elements, but in this case they don’t work for me.
Why, if I turn off change tracking, does ngOnInit not work in nested elements?
Although I can see the child element, it has been rendered. ngOnInit should work.

Parent Component constructor

private cd: ChangeDetectorRef,
      private workerService: WorkerService
) {
    cd.detach();
    ....

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Kadyrov, 2022-01-30
@TwoRS

Look at the documentation ( https://angular.io/api/core/ChangeDetectorRef ) - how the change detection strategy works --> the detach method, when manually controlling change detection, does not block rendering (you wrote that the content was displayed) - but disables change detection ( for example, if asynchronous data flies to the component, then they will not be drawn until the detectChanges command). The OnInit hook fires once only when the change detector first checked the component for changes - and you blocked them manually ( https://angular.io/api/core/OnInit ) - everything is in the docks, read carefully!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question