Skip to content

Commit 660ea81

Browse files
feat: Create both ng1 and ng2 ViewConfig when routing to ng2 component.
closes #1
1 parent 0a33456 commit 660ea81

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

ng1-to-ng2.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import * as angular from "angular";
22
import {provide, ElementRef, Component, Inject, ComponentMetadata} from "angular2/core";
33
import {
4-
UiView, UIRouter, TransitionService, StateService, UIRouterGlobals, UIROUTER_DIRECTIVES, forEach,
5-
UrlRouter, ViewService, StateRegistry, UrlMatcherFactory
4+
UiView, UIRouter, TransitionService, StateService, UIRouterGlobals, UIROUTER_DIRECTIVES, forEach, extend,
5+
UrlRouter, ViewService, StateRegistry, UrlMatcherFactory, Ng2ViewDeclaration, Ng2ViewConfig, Node
66
} from "ui-router-ng2";
77
import {CORE_DIRECTIVES} from "angular2/common";
88
import {UpgradeAdapter} from "angular2/upgrade";
9+
import {Ng1ViewConfig} from "angular-ui-router";
910

1011
export let upgradeModule = angular.module('ui.router.upgrade', ['ui.router']);
1112

@@ -93,6 +94,7 @@ upgradeModule.config([ '$stateProvider', $stateProvider => {
9394
// Update the view config.
9495
// Override default ng1 `component:` behavior (of defining a templateProvider)
9596
// with a <ui-view-ng-upgrade> adapter directive template
97+
viewDecl.$type = "ng1-to-ng2";
9698
viewDecl.templateProvider = null;
9799
viewDecl.template = "<ui-view-ng-upgrade></ui-view-ng-upgrade>";
98100
}
@@ -101,3 +103,13 @@ upgradeModule.config([ '$stateProvider', $stateProvider => {
101103
})
102104
}]);
103105

106+
upgradeModule.run([ '$view', $view => {
107+
$view.viewConfigFactory('ng2', (node: Node, config: Ng2ViewDeclaration) => new Ng2ViewConfig(node, config));
108+
109+
$view.viewConfigFactory('ng1-to-ng2', (node: Node, config: Ng2ViewDeclaration) => {
110+
var ng1ViewConfig = new Ng1ViewConfig(<any> node, <any> Object.assign({}, config, { $type: 'ng1'}));
111+
var ng2ViewConfig = new Ng2ViewConfig(<any> node, <any> Object.assign({}, config, { $type: 'ng2'}));
112+
113+
return [ ng2ViewConfig, ng1ViewConfig ];
114+
});
115+
}]);

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ui-router-ng1-to-ng2",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"scripts": {
55
"build": "npm run clean && npm run tsc",
66
"clean": "rm -f *.d.ts *.js *.js.map",
@@ -11,13 +11,13 @@
1111
"peerDependencies": {
1212
"angular": "^1.5.0",
1313
"angular2": "^2.0.0-beta.13",
14-
"angular-ui-router": "^1.0.0-alpha.4",
14+
"angular-ui-router": "^1.0.0-alpha.5",
1515
"ui-router-ng2": "^1.0.0-alpha.4"
1616
},
1717
"devDependencies": {
1818
"angular": "1.5.3",
1919
"angular2": "2.0.0-beta.13",
20-
"angular-ui-router": "^1.0.0-alpha.4",
20+
"angular-ui-router": "1.0.0-alpha.5",
2121
"es6-shim": "^0.35.0",
2222
"reflect-metadata": "0.1.2",
2323
"rxjs": "5.0.0-beta.2",

0 commit comments

Comments
 (0)