@@ -34,7 +34,6 @@ $stateProvider.state({
34
34
template: ' <h1>Other</h1>' , // AngularJS template/controller
35
35
controller : function ($scope ) { /* do stuff */ }
36
36
})
37
-
38
37
```
39
38
40
39
When routing to an Angular component, that component uses the standard
@@ -70,20 +69,19 @@ We need to use manual AngularJS bootstrapping mode.
70
69
71
70
#### Add AngularJS module ` ui.router.upgrade `
72
71
73
- - Add 'ui.router.upgrade' to your AngularJS app module's depedencies
72
+ * Add 'ui.router.upgrade' to your AngularJS app module's depedencies
74
73
75
74
``` js
76
- let ng1module = angular .module (" myApp" , [' ui.router' , ' ui.router.upgrade' ]);
75
+ let ng1module = angular .module (' myApp' , [' ui.router' , ' ui.router.upgrade' ]);
77
76
```
78
77
79
78
[ _ example_ ] ( https://github.com/ui-router/sample-app-angular-hybrid/blob/e4b1144d5e3e3451f0f0cc640175bb7055294fdd/app/bootstrap/ngmodule.ts#L21-L25 )
80
79
81
80
#### Create a root Angular NgModule
82
81
83
- - Import the ` BrowserModule ` , ` UpgradeModule ` , and a ` UIRouterUpgradeModule.forChild() ` module.
84
- - Add ` providers ` entry for any AngularJS services you want to expose to Angular.
85
- - The module should have a ` ngDoBootstrap ` method which calls the ` UpgradeModule ` 's ` bootstrap ` method.
86
-
82
+ * Import the ` BrowserModule ` , ` UpgradeModule ` , and a ` UIRouterUpgradeModule.forChild() ` module.
83
+ * Add ` providers ` entry for any AngularJS services you want to expose to Angular.
84
+ * The module should have a ` ngDoBootstrap ` method which calls the ` UpgradeModule ` 's ` bootstrap ` method.
87
85
88
86
``` js
89
87
export function getDialogService ($injector ) {
@@ -112,36 +110,42 @@ export function getDialogService($injector) {
112
110
113
111
[ _ example_ ] ( https://github.com/ui-router/sample-app-angular-hybrid/blob/e4b1144d5e3e3451f0f0cc640175bb7055294fdd/app/bootstrap/bootstrap.ts#L63-L73 )
114
112
115
-
116
113
#### Defer intercept
117
114
118
115
Tell UI-Router that it should wait until all bootstrapping is complete before doing the initial URL synchronization.
119
116
120
117
``` js
121
- ngmodule .config ([ ' $urlServiceProvider' , ($urlService : UrlService ) => $urlService .deferIntercept () ]);
118
+ ngmodule .config ([' $urlServiceProvider' , ($urlService : UrlService ) => $urlService .deferIntercept ()]);
122
119
```
123
120
124
121
[ _ example_ ] ( https://github.com/ui-router/sample-app-angular-hybrid/blob/e4b1144d5e3e3451f0f0cc640175bb7055294fdd/app/bootstrap/bootstrap.ts#L75-L76 )
125
122
126
-
127
123
#### Bootstrap the app
128
124
129
- - Bootstrap Angular
130
- - Angular runs ngDoBootstrap() which bootstraps AngularJS
131
- - Chain off ` bootstrapModule() ` and tell UIRouter to synchronize the URL and listen for further URL changes
125
+ * Bootstrap Angular
126
+ * Angular runs ngDoBootstrap() which bootstraps AngularJS
127
+ * Chain off ` bootstrapModule() ` and tell UIRouter to synchronize the URL and listen for further URL changes
128
+ * Do this in the Angular Zone to avoid "digest already in progress" errors.
132
129
133
130
``` js
134
131
// Wait until the DOM is ready
135
- angular .element (document ).ready (function () {
132
+ angular .element (document ).ready (function () {
136
133
// Manually bootstrap the Angular app
137
- platformBrowserDynamic ().bootstrapModule (SampleAppModule).then (platformRef => {
138
- // get() UrlService from DI (this call will create all the UIRouter services)
139
- const url: UrlService = platformRef .injector .get (UrlService);
140
-
141
- // Instruct UIRouter to listen to URL changes
142
- url .listen ();
143
- url .sync ();
144
- });
134
+ platformBrowserDynamic ()
135
+ .bootstrapModule (SampleAppModule)
136
+ .then (platformRef => {
137
+ // get() UrlService from DI (this call will create all the UIRouter services)
138
+ const url: UrlService = platformRef .injector .get (UrlService);
139
+
140
+ // Instruct UIRouter to listen to URL changes
141
+ function startUIRouter () {
142
+ url .listen ();
143
+ url .sync ();
144
+ }
145
+
146
+ const ngZone: NgZone = platformRef .injector .get (NgZone);
147
+ ngZone .run (startUIRouter);
148
+ });
145
149
});
146
150
```
147
151
@@ -188,25 +192,23 @@ $stateProvider.state(leaf);
188
192
@NgModule ({
189
193
imports: [
190
194
UIRouterUpgradeModule .forChild ({
191
- states: [featureState1, featureState2]
192
- })
195
+ states: [featureState1, featureState2],
196
+ }),
193
197
],
194
- declarations: [FeatureComponent1, FeatureComponent2]
198
+ declarations: [FeatureComponent1, FeatureComponent2],
195
199
})
196
200
export class MyFeatureModule {}
197
201
```
198
202
199
203
[ _ example_ ] ( https://github.com/ui-router/sample-app-angular-hybrid/blob/e4b1144d5e3e3451f0f0cc640175bb7055294fdd/app/prefs/index.ts#L11-L22 )
200
204
201
205
Add the feature module to the root NgModule imports
206
+
202
207
``` js
203
208
@NgModule ({
204
- imports: [
205
- BrowserModule,
206
- UIRouterUpgradeModule,
207
- MyFeatureModule
208
- ]
209
- }) class SampleAppModule {}
209
+ imports: [BrowserModule, UIRouterUpgradeModule, MyFeatureModule],
210
+ })
211
+ class SampleAppModule {}
210
212
```
211
213
212
214
[ _ example_ ] ( https://github.com/ui-router/sample-app-angular-hybrid/blob/e4b1144d5e3e3451f0f0cc640175bb7055294fdd/app/bootstrap/bootstrap.ts#L64 )
@@ -216,12 +218,10 @@ Note: You can also add states directly to the root NgModule using `UIRouterModul
216
218
``` js
217
219
@NgModule ({
218
220
// import the Ng1ToNg2Module and create a UIRouter "child module"
219
- imports: [
220
- BrowserModule,
221
- UIRouterUpgradeModule .forChild ({ states: NG2_STATES })
222
- ],
223
- declarations: [NG2_COMPONENTS ]
224
- }) class SampleAppModule {}
221
+ imports: [BrowserModule, UIRouterUpgradeModule .forChild ({ states: NG2_STATES })],
222
+ declarations: [NG2_COMPONENTS ],
223
+ })
224
+ class SampleAppModule {}
225
225
```
226
226
227
227
### Limitations:
@@ -244,9 +244,10 @@ export function ng2StateOnEnter(transition: Transition, svc: MyService) {
244
244
}
245
245
ng2StateOnEnter .$inject = [Transition, ' MyService' ];
246
246
export const NG2_STATE = {
247
- name: ' ng2state' , url: ' /ng2state' ,
248
- onEnter: ng2StateOnEnter
249
- }
247
+ name: ' ng2state' ,
248
+ url: ' /ng2state' ,
249
+ onEnter: ng2StateOnEnter,
250
+ };
250
251
```
251
252
252
253
# Examples
@@ -265,4 +266,3 @@ https://stackblitz.com/github/ui-router/sample-app-angular-hybrid/tree/angular-c
265
266
Version 2.0.0 of ` @uirouter/angular-hybrid ` only supports ` UpgradeAdapter ` , which works fine but is no longer in development.
266
267
Version 30.0+ of ` @uirouter/angular-hybrid ` only supports ` UpgradeModule ` from ` @angular/upgrade/static ` , which is what the Angular team actively supports for hybrid mode.
267
268
Because we dropped support for ` UpgradeAdapter ` , current users of ` @uirouter/angular-hybrid ` 2.x will have to switch to ` UpgradeModule ` when upgrading to 3.x.
268
-
0 commit comments