Skip to content

Commit 58a3c84

Browse files
feat(ng2.stateRegistry): Automatically register states defined on a UIRouterModule
1 parent 0bf4eb4 commit 58a3c84

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/ng2/providers.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ import {services} from "../common/coreservices";
6565
import {ProviderLike} from "../state/interface";
6666
import {Resolvable} from "../resolve/resolvable";
6767
import {ngModuleResolvablesBuilder} from "./statebuilders/lazyLoadNgModuleResolvable";
68+
import {flattenR} from "../common/common";
69+
import {UIROUTER_STATES_TOKEN} from "./uiRouterNgModule";
6870

6971
export const NG1_UIROUTER_TOKEN = new OpaqueToken("$uiRouter");
7072

@@ -110,18 +112,22 @@ let uiRouterFactory = (injector: Injector) => {
110112

111113
// Prep the tree of NgModule by placing the root NgModule's Injector on the root state.
112114
let ng2InjectorResolvable = Resolvable.fromData(NG2_INJECTOR_TOKEN, injector);
113-
router.stateRegistry.root().resolvables.push(ng2InjectorResolvable);
115+
registry.root().resolvables.push(ng2InjectorResolvable);
114116

115117

116118
// ----------------- Initialize router -------------
117119
// Allow states to be registered
118-
router.stateRegistry.stateQueue.autoFlush(router.stateService);
120+
registry.stateQueue.autoFlush(router.stateService);
119121

120122
setTimeout(() => {
121123
// Let the app apply custom configuration...
122124
// (global transition hooks, deferIntercept, otherwise, etc)
123125
routerConfig.configure(router);
124126

127+
// Register the states from the root NgModule [[UIRouterModule]]
128+
let states = (injector.get(UIROUTER_STATES_TOKEN) || []).reduce(flattenR, []);
129+
states.forEach(state => registry.register(state));
130+
125131
// Start monitoring the URL
126132
if (!router.urlRouterProvider.interceptDeferred) {
127133
router.urlRouter.listen();

0 commit comments

Comments
 (0)