Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

fix(ngRoute): allow ngView to be included in an asynchronously loaded template #14088

Closed

Conversation

gkalpak
Copy link
Member

@gkalpak gkalpak commented Feb 19, 2016

During it's linking phase, ngView relies on the info provided in $route.current for instantiating the initial view. $route.current is set in the callback of a listener to $locationChangeSuccess, which is registered during the instantiation of the $route service.

Thus, it is crucial that the $route service is instantiated before the initial $locationChangeSuccess is fired. Since ngView declares $route as a dependency, the service is instantiated in time if ngView is present during the initial load of the page.

Yet, in cases where ngView is included in a template that is loaded asynchronously (e.g. in another directive's template), the directive factory might not be called soon enough for $route to be instantiated before the initial $locationChangeSuccess event is fired.

This commit fixes it, by always instantiating $route up front, during the initialization phase.

Fixes #1213
Fixes #6812

…ed template

During it's linking phase, `ngView` relies on the info provided in `$route.current` for
instantiating the initial view. `$route.current` is set in the callback of a listener to
`$locationChangeSuccess`, which is registered during the instantiation of the `$route` service.

Thus, it is crucial that the `$route` service is instantiated before the initial
`$locationChangeSuccess` is fired. Since `ngView` declares `$route` as a dependency, the service is
instantiated in time if `ngView` is present during the initial load of the page.

Yet, in cases where `ngView` is included in a template that is loaded asynchronously (e.g. in
another directive's template), the directive factory might not be called soon enough for `$route`
to be instantiated before the initial `$locationChangeSuccess` event is fired.

This commit fixes it, by always instantiating `$route` up front, during the initialization phase.

Fixes angular#1213
Fixes angular#6812
@gkalpak gkalpak force-pushed the fix-ngRoute-capture-initial-load branch from 2a639e6 to 3f8b285 Compare February 19, 2016 21:07
@Narretz
Copy link
Contributor

Narretz commented Feb 21, 2016

Would be cool to get this fixed! Does this commit address the problems the first fix for this had? Namely that this caused lots of test failures in a google app because the order of some events changed?

@gkalpak
Copy link
Member Author

gkalpak commented Feb 22, 2016

@Narretz, I'm not aware of the first fix you mention, but I'm quite confident, there won't be any issues with event order. This fix doesn't change the order of any events, it just ensures $route is instantiated early enough to catch the "interesting" events.

@Narretz
Copy link
Contributor

Narretz commented Feb 22, 2016

I found this comment: #1213 (comment)

@gkalpak
Copy link
Member Author

gkalpak commented Feb 22, 2016

Ah, right, I forgot about that. No, this fix just ensures $route is instantiated early (which could be done by any other service/controller/directive or run block anyway), so it set's up it's listeners for $location events in time.

@Narretz
Copy link
Contributor

Narretz commented Feb 24, 2016

Ok, then it LGTM.

gkalpak added a commit that referenced this pull request Feb 25, 2016
…ed template

During it's linking phase, `ngView` relies on the info provided in `$route.current` for
instantiating the initial view. `$route.current` is set in the callback of a listener to
`$locationChangeSuccess`, which is registered during the instantiation of the `$route` service.

Thus, it is crucial that the `$route` service is instantiated before the initial
`$locationChangeSuccess` is fired. Since `ngView` declares `$route` as a dependency, the service is
instantiated in time if `ngView` is present during the initial load of the page.

Yet, in cases where `ngView` is included in a template that is loaded asynchronously (e.g. in
another directive's template), the directive factory might not be called soon enough for `$route`
to be instantiated before the initial `$locationChangeSuccess` event is fired.

This commit fixes it, by always instantiating `$route` up front, during the initialization phase.

Fixes #1213
Fixes #6812

Closes #14088
@gkalpak gkalpak closed this in 5e37b2a Feb 25, 2016
gkalpak added a commit that referenced this pull request Feb 25, 2016
…ed template

During it's linking phase, `ngView` relies on the info provided in `$route.current` for
instantiating the initial view. `$route.current` is set in the callback of a listener to
`$locationChangeSuccess`, which is registered during the instantiation of the `$route` service.

Thus, it is crucial that the `$route` service is instantiated before the initial
`$locationChangeSuccess` is fired. Since `ngView` declares `$route` as a dependency, the service is
instantiated in time if `ngView` is present during the initial load of the page.

Yet, in cases where `ngView` is included in a template that is loaded asynchronously (e.g. in
another directive's template), the directive factory might not be called soon enough for `$route`
to be instantiated before the initial `$locationChangeSuccess` event is fired.

This commit fixes it, by always instantiating `$route` up front, during the initialization phase.

Fixes #1213
Fixes #6812

Closes #14088
@gkalpak
Copy link
Member Author

gkalpak commented Feb 25, 2016

Backported to v1.5.x (8237482) and v1.4.x (88322c1).

@gkalpak gkalpak deleted the fix-ngRoute-capture-initial-load branch February 25, 2016 10:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.