Skip to content

Commit f9b43d6

Browse files
author
Matt Ginzton
committed
fix(ui-view): change $viewContentLoading to pair with $viewContentLoaded
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 #685.
1 parent dba25db commit f9b43d6

File tree

2 files changed

+17
-31
lines changed

2 files changed

+17
-31
lines changed

Diff for: src/view.js

-26
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,6 @@ function $ViewProvider() {
3636
if (options.view) {
3737
result = $templateFactory.fromConfig(options.view, options.params, options.locals);
3838
}
39-
if (result && options.notify) {
40-
/**
41-
* @ngdoc event
42-
* @name ui.router.state.$state#$viewContentLoading
43-
* @eventOf ui.router.state.$view
44-
* @eventType broadcast on root scope
45-
* @description
46-
*
47-
* Fired once the view **begins loading**, *before* the DOM is rendered.
48-
*
49-
* @param {Object} event Event object.
50-
* @param {Object} viewConfig The view config properties (template, controller, etc).
51-
*
52-
* @example
53-
*
54-
* <pre>
55-
* $scope.$on('$viewContentLoading',
56-
* function(event, viewConfig){
57-
* // Access to all the view config properties.
58-
* // and one special property 'targetView'
59-
* // viewConfig.targetView
60-
* });
61-
* </pre>
62-
*/
63-
$rootScope.$broadcast('$viewContentLoading', options);
64-
}
6539
return result;
6640
}
6741
};

Diff for: src/viewDirective.js

+17-5
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,6 @@ function $ViewDirective( $state, $injector, $uiViewScroll, $interpolate)
180180
scope.$on('$stateChangeSuccess', function() {
181181
updateView(false);
182182
});
183-
scope.$on('$viewContentLoading', function() {
184-
updateView(false);
185-
});
186183

187184
updateView(true);
188185

@@ -216,6 +213,20 @@ function $ViewDirective( $state, $injector, $uiViewScroll, $interpolate)
216213
newScope = scope.$new();
217214
latestLocals = $state.$current.locals[name];
218215

216+
/**
217+
* @ngdoc event
218+
* @name ui.router.state.directive:ui-view#$viewContentLoading
219+
* @eventOf ui.router.state.directive:ui-view
220+
* @eventType emits on ui-view directive scope
221+
* @description
222+
*
223+
* Fired once the view **begins loading**, *before* the DOM is rendered.
224+
*
225+
* @param {Object} event Event object.
226+
* @param {string} viewName Name of the view.
227+
*/
228+
newScope.$emit('$viewContentLoading', name);
229+
219230
var clone = $transclude(newScope, function(clone) {
220231
renderer.enter(clone, $element, function onUiViewEnter() {
221232
if(currentScope) {
@@ -236,12 +247,13 @@ function $ViewDirective( $state, $injector, $uiViewScroll, $interpolate)
236247
* @name ui.router.state.directive:ui-view#$viewContentLoaded
237248
* @eventOf ui.router.state.directive:ui-view
238249
* @eventType emits on ui-view directive scope
239-
* @description *
250+
* @description
240251
* Fired once the view is **loaded**, *after* the DOM is rendered.
241252
*
242253
* @param {Object} event Event object.
254+
* @param {string} viewName Name of the view.
243255
*/
244-
currentScope.$emit('$viewContentLoaded');
256+
currentScope.$emit('$viewContentLoaded', name);
245257
currentScope.$eval(onloadExp);
246258
}
247259
};

0 commit comments

Comments
 (0)