ngUpgraders / ng-forward

The default solution for those that want to write Angular 2.x style code in Angular 1.x
410 stars 36 forks source link

in ngAfterViewInit(), child's componentInstance is null with asynchronous template #134

Open rezonant opened 8 years ago

rezonant commented 8 years ago

It appears that if you use templateUrl in a child component, ngAfterViewInit() on the parent component will fire before the child's template is loaded, and thus the componentInstance field will be null for that child.

In my app, simply changing out templateUrl on the component whose componentInstance is null with a template string causes componentInstance to be available. Hopefully I've identified it right since I'm not sure the best way to make a demonstration given the dependencies.

timkindberg commented 8 years ago

Yeah Angular 1 doesn't wait for child template urls to fully load because it might slow the app way down. I'm wondering if there is an easy way we could at least have the hook wait. Honestly I'm not sure how high of a priority this is to me... I highly recommend keeping your templates inline. But I'll do some thinking on this.

timkindberg commented 8 years ago

The child's ngAfterViewInit is not called until it's templateUrl is loaded though right? Its just the parent that is running?

rezonant commented 8 years ago

Just double checked, the ngAfterViewInit() for the child component itself correctly fires after the template is loaded. Just a parent's ngAfterViewInit() is too early for its children to load their templates.