Skip to content

Commit d6d8c33

Browse files
fix(stateBuilder): fix non-url params on a state without a url.
The parameters are now applied when transitioning to a child state. Closes #2025
1 parent 2f1ebef commit d6d8c33

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/state.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
7575

7676
// Derive parameters for this state and ensure they're a super-set of parent's parameters
7777
params: function(state) {
78-
return state.parent && state.parent.params ? extend(state.parent.params.$$new(), state.ownParams) : new $$UMFP.ParamSet();
78+
var ownParams = pick(state.ownParams, state.ownParams.$$keys());
79+
return state.parent && state.parent.params ? extend(state.parent.params.$$new(), ownParams) : new $$UMFP.ParamSet();
7980
},
8081

8182
// If there is no explicit multi-view configuration, make one up so we don't have

test/stateSpec.js

+15
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,21 @@ describe('state', function () {
11231123
expect($state.params).toEqual({ param: "100", param2: "200", param3: "300", param4: "400" });
11241124
expect(count).toEqual(2);
11251125
}));
1126+
1127+
// test for #2025
1128+
it("should be applied on transitions to children, even if the params state has no url", inject(function($state, $q) {
1129+
var count = 0;
1130+
stateProvider.state('nourl', { params: { x: null } });
1131+
stateProvider.state('nourl.child', { url: "/child" });
1132+
$state.go("nourl", { x: "FOO" }); $q.flush();
1133+
1134+
expect($state.current.name).toBe("nourl");
1135+
expect($state.params).toEqualData({ x: "FOO" });
1136+
1137+
$state.go("nourl.child", { x: "FOO" }); $q.flush();
1138+
expect($state.current.name).toBe("nourl.child");
1139+
expect($state.params).toEqualData({ x: "FOO" });
1140+
}));
11261141
});
11271142

11281143
// TODO: Enforce by default in next major release (1.0.0)

0 commit comments

Comments
 (0)