Skip to content

Commit 500299b

Browse files
committed
Merge pull request #295 from excellenteasy/options
getConfig
2 parents 0f5c86c + 96f2c82 commit 500299b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/state.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
222222
exiting = fromPath[l];
223223
if (exiting.self.onExit) {
224224
$injector.invoke(exiting.self.onExit, exiting.self, exiting.locals.globals);
225-
}
225+
}
226226
exiting.locals = null;
227227
}
228228

@@ -279,6 +279,11 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
279279
return !$locationProvider.html5Mode() && url ? "#" + url : url;
280280
};
281281

282+
$state.getConfig = function (stateOrName) {
283+
var state = findState(stateOrName);
284+
return state.self ? angular.copy(state.self) : null;
285+
};
286+
282287
function resolveState(state, params, paramsAreFiltered, inherited, dst) {
283288
// We need to track all the promises generated during the resolution process.
284289
// The first of these is for the fully resolved parent locals.

test/stateSpec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,13 @@ describe('state', function () {
287287
}));
288288
});
289289

290+
describe('.getConfig()', function () {
291+
it("should return a copy of the state's config", inject(function ($state) {
292+
expect($state.getConfig('home').url).toBe('/');
293+
expect($state.getConfig('home.item').url).toBe('front/:id');
294+
}));
295+
});
296+
290297
describe(' "data" property inheritance/override', function () {
291298
it('"data" property should stay immutable for if state doesn\'t have parent', inject(function ($state) {
292299
initStateTo(H);

0 commit comments

Comments
 (0)