From d6d8c3322c4dde8bb5b8dde25f9fcda49e9c4c81 Mon Sep 17 00:00:00 2001 From: christopherthielen Date: Sun, 7 Feb 2016 08:29:16 -0600 Subject: [PATCH] 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 --- src/state.js | 3 ++- test/stateSpec.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/state.js b/src/state.js index bee5efec0..34e4f87d3 100644 --- a/src/state.js +++ b/src/state.js @@ -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 diff --git a/test/stateSpec.js b/test/stateSpec.js index 744e6fee4..fcd52dcef 100644 --- a/test/stateSpec.js +++ b/test/stateSpec.js @@ -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)