Skip to content

Commit 7c54b75

Browse files
fix(ng2): Angular 2.0.0-rc.7 compatibility
Closes #2991
1 parent 73d0a39 commit 7c54b75

File tree

4 files changed

+84
-35
lines changed

4 files changed

+84
-35
lines changed

package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@
5656
},
5757
"license": "MIT",
5858
"devDependencies": {
59-
"@angular/common": "^2.0.0-rc.6",
60-
"@angular/compiler": "^2.0.0-rc.6",
61-
"@angular/core": "^2.0.0-rc.6",
62-
"@angular/platform-browser": "^2.0.0-rc.6",
63-
"@angular/platform-browser-dynamic": "^2.0.0-rc.6",
59+
"@angular/common": "^2.0.0-rc.7",
60+
"@angular/compiler": "^2.0.0-rc.7",
61+
"@angular/core": "^2.0.0-rc.7",
62+
"@angular/platform-browser": "^2.0.0-rc.7",
63+
"@angular/platform-browser-dynamic": "^2.0.0-rc.7",
6464
"babel-core": "^5.8.14",
6565
"clone": "^1.0.2",
6666
"conventional-changelog": "^1.1.0",
@@ -82,7 +82,7 @@
8282
"phantomjs-polyfill": "0.0.1",
8383
"reflect-metadata": "=0.1.2",
8484
"remap-istanbul": "^0.6.3",
85-
"rxjs": "5.0.0-beta.11",
85+
"rxjs": "5.0.0-beta.12",
8686
"shelljs": "^0.7.0",
8787
"systemjs": "^0.18.4",
8888
"ts-loader": "^0.8.1",
@@ -94,6 +94,6 @@
9494
"webpack": "1.x",
9595
"webpack-dev-server": "1.x",
9696
"yargs": "^4.2.0",
97-
"zone.js": "^0.6.17"
97+
"zone.js": "^0.6.21"
9898
}
9999
}

src/ng2/directives/uiView.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @module ng2_directives */ /** */
22
import {
33
Component, ComponentFactoryResolver, ViewContainerRef, Input, ComponentRef, Type,
4-
ReflectiveInjector, InputMetadata, ComponentMetadata, ViewChild, Injector, Inject
4+
ReflectiveInjector, ViewChild, Injector, Inject
55
} from '@angular/core';
66

77
import {UIRouter} from "../../router";
@@ -39,14 +39,14 @@ const ng2ComponentInputs = (ng2CompClass: Type<any>) => {
3939
// -> flattened to [ { key: string, anno: annotation } ] tuples
4040
.reduce((acc, tuple) => acc.concat(tuple.annoArr.map(anno => ({ key: tuple.key, anno }))), [])
4141
// Only Inputs
42-
.filter(tuple => tuple.anno instanceof InputMetadata)
42+
.filter(tuple => tuple.anno instanceof Input)
4343
// If they have a bindingPropertyName, i.e. "@Input('foo') _foo", then foo, else _foo
4444
.map(tuple => ({ token: tuple.anno.bindingPropertyName || tuple.key, prop: tuple.key }));
4545

4646
/** Get "inputs: ['foo']" inputs */
4747
let inputs = Reflect['getMetadata']('annotations', ng2CompClass)
4848
// Find the ComponentMetadata class annotation
49-
.filter(x => x instanceof ComponentMetadata && !!x.inputs)
49+
.filter(x => x instanceof Component && !!x.inputs)
5050
// Get the .inputs string array
5151
.map(x => x.inputs)
5252
.reduce(flattenR, [])

src/ng2/providers.ts

+47-18
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/**
22
* # UI-Router for Angular 2
33
*
4-
* For the quick start repository, please see http://github.com/ui-router/quickstart-ng2
5-
*
4+
* - [ui-router-ng2 home page](https://ui-router.github.io/ng2)
5+
* - [tutorials](https://ui-router.github.io/tutorial/ng2/helloworld)
6+
* - [quick start repository](http://github.com/ui-router/quickstart-ng2)
7+
*
68
* Getting started:
79
*
810
* - Use npm. Add a dependency on latest `ui-router-ng2`
@@ -12,36 +14,63 @@
1214
* import {StateRegistry} from "ui-router-ng2";
1315
* ```
1416
*
15-
* - When defining a component, add the [[UIROUTER_DIRECTIVES]] to `directives:` array.
16-
* - Either bootstrap a [[UIView]] component, or add a `<ui-view></ui-view>` viewport to your root component.
17-
* - Create application states (as defined by [[Ng2StateDeclaration]]) which will fill in the viewports.
18-
* - Create a [[UIRouterConfig]], and register your states in the [[UIRouterConfig.configure]] function.
17+
* - Create application states (as defined by [[Ng2StateDeclaration]]).
18+
*
19+
* ```js
20+
* export let state1 = {
21+
* name: 'state1',
22+
* component: State1Component,
23+
* url: '/one'
24+
* }
25+
*
26+
* export let state2 = {
27+
* name: 'state2',
28+
* component: State2Component,
29+
* url: '/two'
30+
* }
31+
* ```
32+
*
33+
* - Create application feature modules using [[UIRouterModule]]
34+
*
35+
* ```js
36+
* @ UIRouterModule({
37+
* imports: [ CommonModule ],
38+
* states: [ state1, state2 ]
39+
* })
40+
* export class MyFeatureModule {}
41+
* ```
42+
*
43+
* - Optionally create a [[UIRouterConfig]] to perform any pre-bootstrap configuration.
1944
*
2045
* ```js
2146
* import {UIRouter} from "ui-router-ng2";
22-
* import {INITIAL_STATES} from "./app.states";
47+
*
2348
* @ Injectable()
2449
* export class MyUIRouterConfig {
50+
* constructor() {} // Constructor is injectable
2551
* configure(uiRouter: UIRouter) {
26-
* INITIAL_STATES.forEach(function(state) {
27-
* uiRouter.stateRegistry.register(state));
28-
* });
52+
* uiRouter.urlRouterProvider.otherwise(() => uiRouter.stateService.target('home'));
2953
* }
3054
* }
3155
* ```
3256
*
33-
* - When bootstrapping: include the [[UIROUTER_PROVIDERS]] and define a provider for your [[UIRouterConfig]]
57+
* - When bootstrapping the root module: use the [[provideUIRouter]] function:
58+
* - Either bootstrap a [[UIView]] component, or add a `<ui-view></ui-view>` viewport to your root component.
3459
*
3560
* ```js
36-
* import {provide} from "@angular/core";
37-
* import {bootstrap} from 'angular2/platform/browser';
38-
* import {UIRouterConfig, UIView, UIROUTER_PROVIDERS} from "ui-router-ng2";
61+
* import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
62+
* import {UIRouterModule, provideUIRouter, UIView} from "ui-router-ng2";
3963
* import {MyUIRouterConfig} from "./router.config";
4064
*
41-
* bootstrap(UIView, [
42-
* ...UIROUTER_PROVIDERS,
43-
* provide(UIRouterConfig, { useClass: MyUIRouterConfig })
44-
* ]);
65+
* @ UIRouterModule({
66+
* import: [ FeatureModule, BrowserModule ],
67+
* providers: [ provideUIRouter({ configClass: MyUIRouterConfig }) ],
68+
* states: [ homeState ],
69+
* bootstrap: [ UIView ]
70+
* })
71+
* class RootAppModule {}
72+
*
73+
* platformBrowserDynamic().bootstrapModule(RootAppModule);
4574
* ```
4675
*
4776
* @preferred @module ng2

src/ng2/uiRouterNgModule.ts

+27-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @module ng2 */ /** */
22
import {Ng2StateDeclaration} from "./interface";
3-
import {NgModule, NgModuleMetadataType, OpaqueToken} from "@angular/core";
3+
import {NgModule, OpaqueToken} from "@angular/core";
44
import {_UIROUTER_DIRECTIVES} from "./directives/directives";
55
import {_UIROUTER_PROVIDERS} from "./providers";
66
import {UIView} from "./directives/uiView";
@@ -15,12 +15,30 @@ import {uniqR, flattenR} from "../common/common";
1515
export class UIRouterLibraryModule {}
1616

1717
/**
18-
* A module declaration lteral, including UI-Router states.
18+
* A module declaration literal, including UI-Router states.
1919
*
20-
* This interface extends the NG2 [NgModuleMetadataType](https://angular.io/docs/ts/latest/api/core/index/NgModuleMetadataType-interface.html)
20+
* This interface extends the NG2 [NgModule interface](https://angular.io/docs/ts/latest/api/core/index/NgModule-decorator.html)
2121
* by adding a `states` array.
22+
*
23+
* The literal goes inside an `@UIRouterModule` decorator
24+
*
25+
* ---
26+
*
27+
* Although this example demonstrates what the literal is, they are usually
28+
* defined inline instead of as a separate variable:
29+
* ```
30+
* let uiRouterModuleLiteral = {
31+
* providers: [ { provide: LocationStrategy, useClass: HashLocationStrategy } ],
32+
* declarations: [ FooComponent ],
33+
* imports: [ CommonModule ],
34+
* states: [ routerState1, routerState2 ]
35+
* };
36+
*
37+
* @UIRouterModule(uiRouterModuleLiteral)
38+
* class MyModule {}
39+
* ``
2240
*/
23-
export interface UIRouterModuleMetadata extends NgModuleMetadataType {
41+
export interface UIRouterModuleLiteral extends NgModule {
2442
states?: Ng2StateDeclaration[]
2543
}
2644

@@ -57,7 +75,8 @@ export const UIROUTER_STATES_TOKEN = new OpaqueToken("UIRouter States");
5775
* imports: [ BrowserModule ],
5876
* declarations: [ NonRoutedComponent ],
5977
* states: [ homeState, aboutState ]
60-
* }) export class AppModule {};
78+
* })
79+
* export class AppModule {};
6180
* ```
6281
*
6382
* ---
@@ -76,13 +95,14 @@ export const UIROUTER_STATES_TOKEN = new OpaqueToken("UIRouter States");
7695
* providers: [
7796
* { provide: UIROUTER_STATES_TOKEN, useValue: [homeState, aboutState], multi: true }
7897
* ]
79-
* }) export class AppModule {};
98+
* })
99+
* export class AppModule {};
80100
* ```
81101
*
82102
* @param moduleMetaData
83103
* (See also [NgModuleMetadataType](https://angular.io/docs/ts/latest/api/core/index/NgModuleMetadataType-interface.html)
84104
*/
85-
export function UIRouterModule(moduleMetaData: UIRouterModuleMetadata) {
105+
export function UIRouterModule(moduleMetaData: UIRouterModuleLiteral) {
86106
let states = moduleMetaData.states || [];
87107
var statesProvider = { provide: UIROUTER_STATES_TOKEN, useValue: states, multi: true };
88108

0 commit comments

Comments
 (0)