Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Angular 2 Lifecycle equivalent of $postLink?

I'm currently upgrading from Angular.JS (1.5) to Angular 2+. I have come across as $postLink method in an IComponentController and I'm trying to figure out what the equivalent lifecycle hook is in Angular 2+.

like image 660
Eli Sadoff Avatar asked Aug 04 '17 15:08

Eli Sadoff


2 Answers

You are most probably looking for ngAfterViewInit which fires after component and all its child components are initialized.

Of course, it depends on your particular use case as with async data loading there might be some discrepancies which might be needed to be handled differently (for example, monitoring async changes on @Input() properties, but that's another topic).

doc ref: https://angular.io/guide/lifecycle-hooks#lifecycle-sequence

like image 151
dee zg Avatar answered Oct 04 '22 21:10

dee zg


It would be ngAfterViewInit.

$postLink in AngularJS:

We are essentially notified by the hook once all child elements are linked and ready to go

ngAfterViewInit in Angular:

Respond after Angular initializes the component's views and child views.

like image 24
JeB Avatar answered Oct 04 '22 22:10

JeB