Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rezonant opened this issue Jan 12, 2016 · 3 comments

Comments

@rezonant
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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

@rezonant
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants