@@ -51,14 +51,14 @@ Add the `@angular/*` dependencies.
51
51
```
52
52
dependencies: {
53
53
...
54
- "@angular/common": "^4 .0.0",
55
- "@angular/compiler": "^4 .0.0",
56
- "@angular/core": "^4 .0.0",
57
- "@angular/platform-browser": "^4 .0.0",
58
- "@angular/platform-browser-dynamic": "^4 .0.0",
59
- "@angular/upgrade": "^4 .0.0",
54
+ "@angular/common": "^6 .0.0",
55
+ "@angular/compiler": "^6 .0.0",
56
+ "@angular/core": "^6 .0.0",
57
+ "@angular/platform-browser": "^6 .0.0",
58
+ "@angular/platform-browser-dynamic": "^6 .0.0",
59
+ "@angular/upgrade": "^6 .0.0",
60
60
...
61
- "@uirouter/angular-hybrid": "^3 .0.1 ",
61
+ "@uirouter/angular-hybrid": "^6 .0.0 ",
62
62
...
63
63
}
64
64
```
@@ -78,7 +78,7 @@ let ng1module = angular.module('myApp', ['ui.router', 'ui.router.upgrade']);
78
78
79
79
#### Create a root Angular NgModule
80
80
81
- * Import the ` BrowserModule ` , ` UpgradeModule ` , and a ` UIRouterUpgradeModule.forChild () ` module.
81
+ * Import the ` BrowserModule ` , ` UpgradeModule ` , and a ` UIRouterUpgradeModule.forRoot () ` module.
82
82
* Add ` providers ` entry for any AngularJS services you want to expose to Angular.
83
83
* The module should have a ` ngDoBootstrap ` method which calls the ` UpgradeModule ` 's ` bootstrap ` method.
84
84
@@ -90,24 +90,31 @@ export function getDialogService($injector) {
90
90
@NgModule ({
91
91
imports: [
92
92
BrowserModule,
93
+ // Provide angular upgrade capabilities
93
94
UpgradeModule,
94
- UIRouterUpgradeModule .forChild ({ states: ngHybridStates }),
95
+ // Provides the @uirouter/angular directives and registers
96
+ // the future state for the lazy loaded contacts module
97
+ UIRouterUpgradeModule .forRoot ({ states: [contactsFutureState] }),
95
98
],
96
99
providers: [
100
+ // Provide the SystemJsNgModuleLoader when using Angular lazy loading
97
101
{ provide: NgModuleFactoryLoader, useClass: SystemJsNgModuleLoader },
102
+
98
103
// Register some AngularJS services as Angular providers
99
104
{ provide: ' DialogService' , deps: [' $injector' ], useFactory: getDialogService },
105
+ { provide: ' Contacts' , deps: [' $injector' ], useFactory: getContactsService },
100
106
]
101
- }) export class SampleAppModule {
107
+ })
108
+ export class SampleAppModuleAngular {
102
109
constructor (private upgrade : UpgradeModule ) { }
103
110
104
111
ngDoBootstrap () {
105
- this .upgrade .bootstrap (document .body , [sampleAppModuleAngularJS .name ]);
112
+ this .upgrade .bootstrap (document .body , [sampleAppModuleAngularJS .name ], { strictDi : true } );
106
113
}
107
114
}
108
115
```
109
116
110
- [ _ example_ ] ( https://github.com/ui-router/sample-app-angular-hybrid/blob/e4b1144d5e3e3451f0f0cc640175bb7055294fdd /app/bootstrap/bootstrap .ts#L63-L73 )
117
+ [ _ example_ ] ( https://github.com/ui-router/sample-app-angular-hybrid/blob/878095bc7ed1948bb8ebf6e67d77724354393455 /app/angularModule .ts#L26-L53 )
111
118
112
119
#### Defer intercept
113
120
@@ -117,7 +124,7 @@ Tell UI-Router that it should wait until all bootstrapping is complete before do
117
124
ngmodule .config ([' $urlServiceProvider' , ($urlService : UrlService ) => $urlService .deferIntercept ()]);
118
125
```
119
126
120
- [ _ example_ ] ( https://github.com/ui-router/sample-app-angular-hybrid/blob/e4b1144d5e3e3451f0f0cc640175bb7055294fdd /app/bootstrap/bootstrap .ts#L75-L76 )
127
+ [ _ example_ ] ( https://github.com/ui-router/sample-app-angular-hybrid/blob/878095bc7ed1948bb8ebf6e67d77724354393455 /app/main .ts#L38-L40 )
121
128
122
129
#### Bootstrap the app
123
130
@@ -127,28 +134,24 @@ ngmodule.config(['$urlServiceProvider', ($urlService: UrlService) => $urlService
127
134
* Do this in the Angular Zone to avoid "digest already in progress" errors.
128
135
129
136
``` js
130
- // Wait until the DOM is ready
131
- angular .element (document ).ready (function () {
132
- // Manually bootstrap the Angular app
133
- platformBrowserDynamic ()
134
- .bootstrapModule (SampleAppModule)
135
- .then (platformRef => {
136
- // get() UrlService from DI (this call will create all the UIRouter services)
137
- const url: UrlService = platformRef .injector .get (UrlService);
138
-
139
- // Instruct UIRouter to listen to URL changes
140
- function startUIRouter () {
141
- url .listen ();
142
- url .sync ();
143
- }
144
-
145
- const ngZone: NgZone = platformRef .injector .get (NgZone);
146
- ngZone .run (startUIRouter);
147
- });
148
- });
137
+ platformBrowserDynamic ()
138
+ .bootstrapModule (SampleAppModuleAngular)
139
+ .then (platformRef => {
140
+ // Intialize the Angular Module
141
+ // get() the UIRouter instance from DI to initialize the router
142
+ const urlService: UrlService = platformRef .injector .get (UIRouter).urlService ;
143
+
144
+ // Instruct UIRouter to listen to URL changes
145
+ function startUIRouter () {
146
+ urlService .listen ();
147
+ urlService .sync ();
148
+ }
149
+
150
+ platformRef .injector .get < NgZone > NgZone .run (startUIRouter);
151
+ });
149
152
```
150
153
151
- [ _ example_ ] ( https://github.com/ui-router/sample-app-angular-hybrid/blob/e4b1144d5e3e3451f0f0cc640175bb7055294fdd /app/bootstrap/bootstrap .ts#L78-L95 )
154
+ [ _ example_ ] ( https://github.com/ui-router/sample-app-angular-hybrid/blob/878095bc7ed1948bb8ebf6e67d77724354393455 /app/main .ts#L42-L55 )
152
155
153
156
#### Route to AngularJS components/templates
154
157
@@ -199,29 +202,18 @@ $stateProvider.state(leaf);
199
202
export class MyFeatureModule {}
200
203
```
201
204
202
- [ _ example_ ] ( https://github.com/ui-router/sample-app-angular-hybrid/blob/e4b1144d5e3e3451f0f0cc640175bb7055294fdd /app/prefs/index. ts#L11-L22 )
205
+ [ _ example_ ] (https://github.com/ui-router/sample-app-angular-hybrid/blob/878095bc7ed1948bb8ebf6e67d77724354393455 /app/prefs/prefs.module. ts#L10-L21
203
206
204
207
Add the feature module to the root NgModule imports
205
208
206
209
``` js
207
210
@NgModule ({
208
- imports: [BrowserModule, UIRouterUpgradeModule, MyFeatureModule],
211
+ imports: [BrowserModule, UIRouterUpgradeModule . forChild ({ states }) , MyFeatureModule],
209
212
})
210
213
class SampleAppModule {}
211
214
```
212
215
213
- [ _ example_ ] ( https://github.com/ui-router/sample-app-angular-hybrid/blob/e4b1144d5e3e3451f0f0cc640175bb7055294fdd/app/bootstrap/bootstrap.ts#L64 )
214
-
215
- Note: You can also add states directly to the root NgModule using ` UIRouterModule.forChild `
216
-
217
- ``` js
218
- @NgModule ({
219
- // import the Ng1ToNg2Module and create a UIRouter "child module"
220
- imports: [BrowserModule, UIRouterUpgradeModule .forChild ({ states: NG2_STATES })],
221
- declarations: [NG2_COMPONENTS ],
222
- })
223
- class SampleAppModule {}
224
- ```
216
+ [ _ example_ ] ( https://github.com/ui-router/sample-app-angular-hybrid/blob/878095bc7ed1948bb8ebf6e67d77724354393455/app/angularModule.ts#L35-L36 )
225
217
226
218
### Limitations:
227
219
@@ -235,7 +227,7 @@ Because of this, apps should be migrated starting from leaf states/views and wor
235
227
---
236
228
237
229
When a state has an ` onEnter ` , ` onExit ` , or ` onRetain ` , they are always injected (AngularJS style),
238
- even if the state uses Angular 2+ components or is added to an ` UIRouterUpgradeModule.forChild ` ` NgModule ` .
230
+ even if the state uses Angular 2+ components or is added to an ` UIRouterUpgradeModule ` ` NgModule ` .
239
231
240
232
``` js
241
233
export function ng2StateOnEnter (transition : Transition , svc : MyService ) {
@@ -254,7 +246,10 @@ export const NG2_STATE = {
254
246
The minimal example of ` @uirouter/angular-hybrid ` can be found here:
255
247
https://github.com/ui-router/angular-hybrid/tree/master/example
256
248
257
- A full fledged sample application example can be found here:
249
+ A minimal example can also be found on stackblitz:
250
+ https://stackblitz.com/edit/ui-router-angular-hybrid
251
+
252
+ A large sample application example with lazy loaded modules can be found here:
258
253
https://github.com/ui-router/sample-app-angular-hybrid
259
254
260
255
The same sample application can be live-edited using Angular CLI and StackBlitz here:
@@ -263,5 +258,5 @@ https://stackblitz.com/github/ui-router/sample-app-angular-hybrid/tree/angular-c
263
258
# UpgradeAdapter vs UpgradeModule
264
259
265
260
Version 2.0.0 of ` @uirouter/angular-hybrid ` only supports ` UpgradeAdapter ` , which works fine but is no longer in development.
266
- 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.
261
+ Version 3.0 .0+ of ` @uirouter/angular-hybrid ` only supports ` UpgradeModule ` from ` @angular/upgrade/static ` , which is what the Angular team actively supports for hybrid mode.
267
262
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.
0 commit comments