Skip to content

Commit

Permalink
feat: Create both ng1 and ng2 ViewConfig when routing to ng2 component.
Browse files Browse the repository at this point in the history
closes #1
  • Loading branch information
christopherthielen committed Apr 9, 2016
1 parent 0a33456 commit 660ea81
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
16 changes: 14 additions & 2 deletions ng1-to-ng2.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as angular from "angular";
import {provide, ElementRef, Component, Inject, ComponentMetadata} from "angular2/core";
import {
UiView, UIRouter, TransitionService, StateService, UIRouterGlobals, UIROUTER_DIRECTIVES, forEach,
UrlRouter, ViewService, StateRegistry, UrlMatcherFactory
UiView, UIRouter, TransitionService, StateService, UIRouterGlobals, UIROUTER_DIRECTIVES, forEach, extend,
UrlRouter, ViewService, StateRegistry, UrlMatcherFactory, Ng2ViewDeclaration, Ng2ViewConfig, Node
} from "ui-router-ng2";
import {CORE_DIRECTIVES} from "angular2/common";
import {UpgradeAdapter} from "angular2/upgrade";
import {Ng1ViewConfig} from "angular-ui-router";

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

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

upgradeModule.run([ '$view', $view => {
$view.viewConfigFactory('ng2', (node: Node, config: Ng2ViewDeclaration) => new Ng2ViewConfig(node, config));

$view.viewConfigFactory('ng1-to-ng2', (node: Node, config: Ng2ViewDeclaration) => {
var ng1ViewConfig = new Ng1ViewConfig(<any> node, <any> Object.assign({}, config, { $type: 'ng1'}));
var ng2ViewConfig = new Ng2ViewConfig(<any> node, <any> Object.assign({}, config, { $type: 'ng2'}));

return [ ng2ViewConfig, ng1ViewConfig ];
});
}]);
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ui-router-ng1-to-ng2",
"version": "1.0.3",
"version": "1.0.4",
"scripts": {
"build": "npm run clean && npm run tsc",
"clean": "rm -f *.d.ts *.js *.js.map",
Expand All @@ -11,13 +11,13 @@
"peerDependencies": {
"angular": "^1.5.0",
"angular2": "^2.0.0-beta.13",
"angular-ui-router": "^1.0.0-alpha.4",
"angular-ui-router": "^1.0.0-alpha.5",
"ui-router-ng2": "^1.0.0-alpha.4"
},
"devDependencies": {
"angular": "1.5.3",
"angular2": "2.0.0-beta.13",
"angular-ui-router": "^1.0.0-alpha.4",
"angular-ui-router": "1.0.0-alpha.5",
"es6-shim": "^0.35.0",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.2",
Expand Down

0 comments on commit 660ea81

Please sign in to comment.