Skip to content

Commit 74255fe

Browse files
fix($state): do not emit $viewContentLoading if notify: false
- pass options.notify to $view.load() from $state.go(), i.e.: $state.go($state.current.name, { }, { notify: false}) Closes #1387
1 parent 4533fe3 commit 74255fe

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/state.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
860860

861861
for (var l = keep; l < toPath.length; l++, state = toPath[l]) {
862862
locals = toLocals[l] = inherit(locals);
863-
resolved = resolveState(state, toParams, state === to, resolved, locals);
863+
resolved = resolveState(state, toParams, state === to, resolved, locals, options);
864864
}
865865

866866
// Once everything is resolved, we are ready to perform the actual transition
@@ -1149,7 +1149,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
11491149
return (state && state.self) ? state.self : null;
11501150
};
11511151

1152-
function resolveState(state, params, paramsAreFiltered, inherited, dst) {
1152+
function resolveState(state, params, paramsAreFiltered, inherited, dst, options) {
11531153
// Make a restricted $stateParams with only the parameters that apply to this state if
11541154
// necessary. In addition to being available to the controller and onEnter/onExit callbacks,
11551155
// we also need $stateParams to be available for any $injector calls we make during the
@@ -1171,7 +1171,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
11711171
forEach(state.views, function (view, name) {
11721172
var injectables = (view.resolve && view.resolve !== state.resolve ? view.resolve : {});
11731173
injectables.$template = [ function () {
1174-
return $view.load(name, { view: view, locals: locals, params: $stateParams }) || '';
1174+
return $view.load(name, { view: view, locals: locals, params: $stateParams, notify: options.notify }) || '';
11751175
}];
11761176

11771177
promises.push($resolve.resolve(injectables, locals, dst.resolve, state).then(function (result) {

test/stateSpec.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ describe('state', function () {
2222
C = {},
2323
D = { params: { x: null, y: null } },
2424
DD = { parent: D, params: { x: null, y: null, z: null } },
25+
DDDD = { parent: D, controller: function() {}, template: "hey"},
2526
E = { params: { i: {} } },
2627
H = { data: {propA: 'propA', propB: 'propB'} },
2728
HH = { parent: H },
@@ -44,6 +45,7 @@ describe('state', function () {
4445
.state('C', C)
4546
.state('D', D)
4647
.state('DD', DD)
48+
.state('DDDD', DDDD)
4749
.state('E', E)
4850
.state('H', H)
4951
.state('HH', HH)
@@ -332,28 +334,24 @@ describe('state', function () {
332334
expect($state.current).toBe(D);
333335
}));
334336

335-
it('does not trigger $stateChangeSuccess when suppressed, but changes state', inject(function ($state, $q, $rootScope) {
337+
it('does not trigger $stateChangeSuccess or $viewContentLoading when suppressed, but changes state', inject(function ($state, $q, $rootScope, $httpBackend) {
336338
initStateTo(E, { i: 'iii' });
337339
var called;
338340

339-
$rootScope.$on('$stateChangeSuccess', function (ev, to, toParams, from, fromParams) {
340-
called = true;
341-
});
342-
343-
$state.transitionTo(D, { x: '1', y: '2' }, { notify: false });
341+
$rootScope.$on('$stateChangeSuccess', function () { called = true; });
342+
$rootScope.$on('$viewContentLoading', function (evt, foo) { called = true; });
343+
$state.transitionTo(DDDD, {}, { notify: false });
344344
$q.flush();
345345

346346
expect(called).toBeFalsy();
347-
expect($state.current).toBe(D);
347+
expect($state.current).toBe(DDDD);
348348
}));
349349

350350
it('does not trigger $stateChangeSuccess when suppressed, but updates params', inject(function ($state, $q, $rootScope) {
351351
initStateTo(E, { x: 'iii' });
352352
var called;
353353

354-
$rootScope.$on('$stateChangeSuccess', function (ev, to, toParams, from, fromParams) {
355-
called = true;
356-
});
354+
$rootScope.$on('$stateChangeSuccess', function () { called = true; });
357355
$state.transitionTo(E, { i: '1', y: '2' }, { notify: false });
358356
$q.flush();
359357

@@ -748,6 +746,7 @@ describe('state', function () {
748746
'C',
749747
'D',
750748
'DD',
749+
'DDDD',
751750
'E',
752751
'H',
753752
'HH',

0 commit comments

Comments
 (0)