-
Notifications
You must be signed in to change notification settings - Fork 3k
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
event $viewContentLoading doesn't seem to work #685
Comments
If you haven't already, double check that your controller is being instantiated and/or listen for $stateChageError from your run function. |
I can surely tell that the controller gets istantiated because in this code
The event I'm experiencing this problem with Angular 1.2.2 as well as 1.2.5 |
I actually couldn't this to work at all either. I think it may be just plain broke. |
Not really broken. I think. Take a look at this line. |
@dmatteo The Long story short:
.state('users', {
controller: UsersController,
resolve: {
users: function() {
return [ /* ... */ ];
}
}
});
function UsersController($scope) {
console.log("UsersController instantiated");
$scope.$on('$viewContentLoading', function(event, viewConfig){
console.log('content loading: ', event, viewConfig)
});
$scope.$on('$viewContentLoaded', function(event){
console.log('content loaded!')
});
}
app.controller('UsersController', ['$scope', UsersController]); You can instantiate a parent controller right in your view and setup the view loading delegate. <div class="users" ng-controller="LoadingIndicatorController">
<div class="contents" ui-view></div>
</div> function LoadingIndicatorController($scope) {
console.log("LoadingIndicatorController instantiated");
$scope.$on('$viewContentLoading',function(event, viewConfig){
console.log("Contents will load.");
});
$scope.$on('$viewContentLoaded',function(event, viewConfig){
console.log("Contents did load.");
});
}
app.controller('LoadingIndicatorController', ['$scope', LoadingIndicatorController]); That even doesn't work because of the issue that @gustavohenke points out. I still had to hack a |
@vicentereig Are you saying this is how it currently works, or how it should work? My gut is that this is just broken on accident, but perhaps someone set notify to false for a different reason, not realizing it would stop the $viewContentLoading event from firing. I'm also not completely sure I even understand why and when you'd even need the $viewContentLoading event! |
+1 |
@timkindberg Sorry for the late reply. What I mean is that this is how it currently works. To recap:
I've got some views that take a little while to load the data from the server (sometimes ~1 second), so I wanted to show a loading indicator while transitioning from one route to another. I'm aware of other ways to render it while loading the data. But if routes are responsible of defining the UI state by putting together the controller, template, and data coming from the resolve section, I find it natural to let them notify whoever wants to listen it to it about the current status of the loading process. My use caseMy use case is a Master-Detail view drilldown interaction. Let's say I've got the following
Maybe I'm missing something, but when I first point the browser
Talk you soon, |
Yes, the use case makes sense now. Hopefully we'll be able to get to this in 0.4.0. |
+1 |
2 similar comments
+1 |
+1 |
Facing with the same issue due to exact same reason. so, another +1. |
+1 - in fact, handling $viewContentLoading is a core need in my using dynamic templateUrls, since I need to do a bit of post-processing on the load and wanted it to happen before it's placed in the view. |
+1 For me the event isn't trigger the first time, after that perfect. Anybody have a hack for this? cheers. |
For me too $viewContentLoaded is not firing. How the heck should i know that my view is ready? |
Still waiting on a plunkr that demonstrates the issue. |
+1 |
2 similar comments
+1 |
+1 |
Not firing, too :( |
I think the problem is that the
The problem is if you have nested views and states such that you can update views without activating new states (such as transitioning from a child state to a parent state, which involves only state DEactivation) then you get |
I also note in real usage in my real apps that when Proposal 1: leave Proposal 2: remove the existing I'd favor proposal 2 because I don't know what the meaning of the existing I'd be happy to submit a PR for either of these proposals if the main contributors would nominate their preference. |
A couple other differences I note between
Again if there's a need (for backwards compatibility or for internal reasons I don't understand) for the current @nateabele please note the new plunkr in response to the plunkr-please label, and I'm curious what you think of this analysis and the proposals. |
The old $viewContentLoaded event wasn't needed for the one internal client (ui-view) because ui-view always ignores that event and acts on a $stateChangeSuccess event that follows right behind anyway. And it wasn't as useful to external clients as it could be because it wasn't delivered on every view update -- it was delivered only on state transitions that activate a state defining a view, and didn't deal with inheritance. Also, neither $viewContentLoading nor $viewContentLoaded events contained the name of the view loading or loaded. This change makes $viewContentLoading and $viewContentLoaded be emitted always in pairs, before/after updateView does the work of actually loading the view, and both events include the name of the view being loaded. This is a breaking change for users of the old $viewContentLoading event that relied on it being broadcast from the root scope, the precise time it was broadcast, the fact that it wasn't always sent when a view is loaded even if $viewContentLoaded will be sent, or the "options" parameter that was emitted with it. If people rely on any of that behavior and we can't break it, then we can restore the old behavior but I think there needs to be some other event which is reliably paired with $viewContentLoaded and contains the view name, and I can't think of a better name than $viewContentLoading for that event. Closes angular-ui#685.
I updated the plunkr to demonstrate that if one state has two child views, and a child state populates both those views, you get two "loading" and two "loaded" events, but if a child state populates only one of those views, you get one "loading" and two "loaded" events. The problem I understand is related to situations with multiple views defined across multiple states with inheritance. The inherited views get a "loaded" event but no "loading" event. |
Metamatt Thanks for the analysis. I've never understood how people are using these events external to ui-router code. I think option #2 seems reasonable. Can anyone else speak up if they are using viewContentLoading in some meaningful way and would object to proposal #2? That said, Nate is revamping the transition to view interaction, and these events are likely going to be deprecated or removed completely in 1.x. |
To those who requested use cases — take a look at my original issue: #2403 and [finally] working example: http://plnkr.co/edit/ED0SGYyJerO1kaNDCwGv?p=preview This requires the patch from: #2003 |
No actually, I just leaved a message for those seeking additional information. |
Ah, okay. 😄 Thanks! |
The old $viewContentLoaded event wasn't needed for the one internal client (ui-view) because ui-view always ignores that event and acts on a $stateChangeSuccess event that follows right behind anyway. And it wasn't as useful to external clients as it could be because it wasn't delivered on every view update -- it was delivered only on state transitions that activate a state defining a view, and didn't deal with inheritance. Also, neither $viewContentLoading nor $viewContentLoaded events contained the name of the view loading or loaded. This change makes $viewContentLoading and $viewContentLoaded be emitted always in pairs, before/after updateView does the work of actually loading the view, and both events include the name of the view being loaded. This is a breaking change for users of the old $viewContentLoading event that relied on it being broadcast from the root scope, the precise time it was broadcast, the fact that it wasn't always sent when a view is loaded even if $viewContentLoaded will be sent, or the "options" parameter that was emitted with it. If people rely on any of that behavior and we can't break it, then we can restore the old behavior but I think there needs to be some other event which is reliably paired with $viewContentLoaded and contains the view name, and I can't think of a better name than $viewContentLoading for that event. Closes angular-ui#685.
The old $viewContentLoaded event wasn't needed for the one internal client (ui-view) because ui-view always ignores that event and acts on a $stateChangeSuccess event that follows right behind anyway. And it wasn't as useful to external clients as it could be because it wasn't delivered on every view update -- it was delivered only on state transitions that activate a state defining a view, and didn't deal with inheritance. Also, neither $viewContentLoading nor $viewContentLoaded events contained the name of the view loading or loaded. This change makes $viewContentLoading and $viewContentLoaded be emitted always in pairs, before/after updateView does the work of actually loading the view, and both events include the name of the view being loaded. This is a breaking change for users of the old $viewContentLoading event that relied on it being broadcast from the root scope, the precise time it was broadcast, the fact that it wasn't always sent when a view is loaded even if $viewContentLoaded will be sent, or the "options" parameter that was emitted with it. If people rely on any of that behavior and we can't break it, then we can restore the old behavior but I think there needs to be some other event which is reliably paired with $viewContentLoaded and contains the view name, and I can't think of a better name than $viewContentLoading for that event. Closes angular-ui#685.
It seems I'm unable to get the
$viewContentLoading
fired.The doc says it's fired by the
$rootScope
, while in the example listen to the$scope
I've tried both, but I couldn't catch any event
The text was updated successfully, but these errors were encountered: