-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathproviders.ts
116 lines (98 loc) · 3.96 KB
/
providers.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
* # UI-Router for Angular 2
*
* For the quick start repository, please see http://github.com/ui-router/quickstart-ng2
*
* Getting started:
*
* - Use npm. Add a dependency on latest `ui-router-ng2`
* - Import UI-Router classes directly from `"ui-router-ng2"`
*
* ```js
* import {StateRegistry} from "ui-router-ng2";
* ```
*
* - When defining a component, add the [[UIROUTER_DIRECTIVES]] to `directives:` array.
* - Either bootstrap a [[UiView]] component, or add a `<ui-view></ui-view>` viewport to your root component.
* - Create application states (as defined by [[Ng2StateDeclaration]]) which will fill in the viewports.
* - Create a [[UIRouterConfig]], and register your states in the [[UIRouterConfig.configure]] function.
*
* ```js
* import {UIRouter} from "ui-router-ng2";
* import {INITIAL_STATES} from "./app.states";
* @ Injectable()
* export class MyUIRouterConfig {
* configure(uiRouter: UIRouter) {
* INITIAL_STATES.forEach(function(state) {
* uiRouter.stateRegistry.register(state));
* });
* }
* }
* ```
*
* - When bootstrapping: include the [[UIROUTER_PROVIDERS]] and define a provider for your [[UIRouterConfig]]
*
* ```js
* import {provide} from "angular2/core";
* import {bootstrap} from 'angular2/platform/browser';
* import {UIRouterConfig, UiView, UIROUTER_PROVIDERS} from "ui-router-ng2";
* import {MyUIRouterConfig} from "./router.config";
*
* bootstrap(UiView, [
* ...UIROUTER_PROVIDERS,
* provide(UIRouterConfig, { useClass: MyUIRouterConfig })
* ]);
* ```
*
* @preferred @module ng2
*/ /** */
import {Provider, provide} from "angular2/core";
import {UIRouter} from "../router";
import {Node} from "../path/node";
import {StateRegistry} from "../state/stateRegistry";
import {StateService} from "../state/stateService";
import {TransitionService} from "../transition/transitionService";
import {UrlMatcherFactory} from "../url/urlMatcherFactory";
import {UrlRouter} from "../url/urlRouter";
import {ViewService} from "../view/view";
import {UiView} from "./uiView";
import {ng2ViewsBuilder, Ng2ViewConfig} from "./viewsBuilder";
import {Ng2ViewDeclaration} from "./interface";
import {UIRouterConfig} from "./uiRouterConfig";
import {UIRouterGlobals} from "../globals";
let uiRouterFactory = (routerConfig: UIRouterConfig) => {
let router = new UIRouter();
router.viewService.viewConfigFactory("ng2", (node: Node, config: Ng2ViewDeclaration) => new Ng2ViewConfig(node, config));
router.stateRegistry.decorator('views', ng2ViewsBuilder);
router.stateRegistry.stateQueue.autoFlush(router.stateService);
routerConfig.configure(router);
if (!router.urlRouterProvider.interceptDeferred) {
router.urlRouter.listen();
router.urlRouter.sync();
}
return router;
};
/**
* The UI-Router providers, for use in your application bootstrap
*
* @example
* ```js
*
* bootstrap(UiView, [
* ...UIROUTER_PROVIDERS,
* ...HTTP_PROVIDERS,
* provide(UIRouterConfig, { useClass: MyUIRouterConfig })
* ]);
* ```
*/
export const UIROUTER_PROVIDERS: Provider[] = [
provide(UIRouter, { useFactory: uiRouterFactory, deps: [UIRouterConfig] }),
provide(StateService, { useFactory: (r: UIRouter) => { return r.stateService; }, deps: [UIRouter]}),
provide(TransitionService, { useFactory: (r: UIRouter) => { return r.transitionService; }, deps: [UIRouter]}),
provide(UrlMatcherFactory, { useFactory: (r: UIRouter) => { return r.urlMatcherFactory; }, deps: [UIRouter]}),
provide(UrlRouter, { useFactory: (r: UIRouter) => { return r.urlRouter; }, deps: [UIRouter]}),
provide(ViewService, { useFactory: (r: UIRouter) => { return r.viewService; }, deps: [UIRouter]}),
provide(StateRegistry, { useFactory: (r: UIRouter) => { return r.stateRegistry; }, deps: [UIRouter]}),
provide(UIRouterGlobals, { useFactory: (r: UIRouter) => { return r.globals; }, deps: [UIRouter]}),
provide(UiView.PARENT_INJECT, { useFactory: (r: StateRegistry) => { return { fqn: null, context: r.root() } }, deps: [StateRegistry]} )
];