Skip to content

Commit

Permalink
fix(stateBuilder): fix non-url params on a state without a url.
Browse files Browse the repository at this point in the history
The parameters are now applied when transitioning to a child state.
Closes #2025
  • Loading branch information
christopherthielen committed Feb 7, 2016
1 parent 2f1ebef commit d6d8c33
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {

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

// If there is no explicit multi-view configuration, make one up so we don't have
Expand Down
15 changes: 15 additions & 0 deletions test/stateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,21 @@ describe('state', function () {
expect($state.params).toEqual({ param: "100", param2: "200", param3: "300", param4: "400" });
expect(count).toEqual(2);
}));

// test for #2025
it("should be applied on transitions to children, even if the params state has no url", inject(function($state, $q) {
var count = 0;
stateProvider.state('nourl', { params: { x: null } });
stateProvider.state('nourl.child', { url: "/child" });
$state.go("nourl", { x: "FOO" }); $q.flush();

expect($state.current.name).toBe("nourl");
expect($state.params).toEqualData({ x: "FOO" });

$state.go("nourl.child", { x: "FOO" }); $q.flush();
expect($state.current.name).toBe("nourl.child");
expect($state.params).toEqualData({ x: "FOO" });
}));
});

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

0 comments on commit d6d8c33

Please sign in to comment.