11import * as angular from "angular" ;
22import { provide , ElementRef , Component , Inject , ComponentMetadata } from "@angular/core" ;
33import { UpgradeAdapter } from "@angular/upgrade" ;
4+
5+ import { Ng1ViewConfig , StateProvider , State } from "angular-ui-router" ;
6+
47import {
5- UIView , UIRouter , TransitionService , StateService , Globals , UIROUTER_DIRECTIVES , forEach , extend ,
6- UrlRouter , ViewService , StateRegistry , UrlMatcherFactory , Ng2ViewDeclaration , Ng2ViewConfig , PathNode
8+ UIView , UIRouter , TransitionService , StateService , Globals , UIROUTER_DIRECTIVES , forEach ,
9+ UrlRouter , ViewService , StateRegistry , UrlMatcherFactory , Ng2ViewDeclaration , Ng2ViewConfig , PathNode ,
10+ ParentUIViewInject , ViewConfig
711} from "ui-router-ng2" ;
8- import { Ng1ViewConfig } from "angular-ui-router" ;
912
1013export let upgradeModule = angular . module ( 'ui.router.upgrade' , [ 'ui.router' ] ) ;
1114
15+ declare var Reflect : any ;
16+
1217@Component ( {
1318 selector : 'ui-view-ng-upgrade' ,
1419 template : `<ui-view></ui-view>` ,
@@ -22,7 +27,7 @@ export let upgradeModule = angular.module('ui.router.upgrade', ['ui.router']);
2227 * up the DOM and grabbing the .data('$uiView') that the ng1 ui-view directive provided.
2328 */
2429class UIViewNgUpgrade {
25- constructor ( ref : ElementRef , @Inject ( UIView . PARENT_INJECT ) parent , registry : StateRegistry ) {
30+ constructor ( ref : ElementRef , @Inject ( UIView . PARENT_INJECT ) parent : ParentUIViewInject , registry : StateRegistry ) {
2631 // From the ui-view-ng-upgrade component's element ref, walk up the DOM two elements...
2732 // There will first be one ng1 ui-view which hosts this element, and then that ui-view's
2833 // parent element. This element has access to the proper "parent viewcontext"
@@ -73,14 +78,14 @@ export let uiRouterNgUpgrade = {
7378/**
7479 * Predicate that returns true if an object is a NG2 Component Class
7580 */
76- export function isNg2ComponentClass ( def ) {
81+ export function isNg2ComponentClass ( def : any ) {
7782 if ( typeof def !== 'function' ) return false ;
7883
7984 if ( ! Reflect || typeof Reflect [ 'metadata' ] !== 'function' )
8085 throw new Error ( "Missing runtime dependency: 'reflect-metadata'" ) ;
8186
8287 return Reflect [ 'getMetadata' ] ( 'annotations' , def )
83- . find ( x => x instanceof ComponentMetadata ) ;
88+ . find ( ( x : any ) => x instanceof ComponentMetadata ) ;
8489}
8590
8691/**
@@ -90,11 +95,11 @@ export function isNg2ComponentClass(def) {
9095 * In place of the template provider, it simply puts a <ui-view-ng-upgrade/> component, which is the
9196 * downgraded Ng2 Component that provides a ng1-to-ng2 boundary in the DOM.
9297 */
93- upgradeModule . config ( [ '$stateProvider' , $stateProvider => {
94- $stateProvider . decorator ( 'views' , function ( state /*: Ng1StateDeclaration */ , parentFn : Function ) {
98+ upgradeModule . config ( [ '$stateProvider' , ( $stateProvider : StateProvider ) => {
99+ $stateProvider . decorator ( 'views' , function ( state : State , parentFn : Function ) {
95100 let views = parentFn ( state ) ;
96101
97- forEach ( views , ( viewDecl /*: Ng1ViewDeclaration */ , viewName : string ) => {
102+ forEach ( views , ( viewDecl : any , viewName : string ) => {
98103 if ( isNg2ComponentClass ( viewDecl . component ) ) {
99104 // Update the view config.
100105 // Override default ng1 `component:` behavior (of defining a templateProvider)
@@ -108,12 +113,12 @@ upgradeModule.config([ '$stateProvider', $stateProvider => {
108113 } )
109114} ] ) ;
110115
111- upgradeModule . run ( [ '$view' , $view => {
116+ upgradeModule . run ( [ '$view' , ( $view : ViewService ) => {
112117 $view . viewConfigFactory ( 'ng2' , ( path : PathNode [ ] , config : Ng2ViewDeclaration ) => new Ng2ViewConfig ( path , config ) ) ;
113118
114- $view . viewConfigFactory ( 'ng1-to-ng2' , ( node : PathNode , config : Ng2ViewDeclaration ) => {
115- var ng1ViewConfig = new Ng1ViewConfig ( < any > node , < any > Object . assign ( { } , config , { $type : 'ng1' } ) ) ;
116- var ng2ViewConfig = new Ng2ViewConfig ( < any > node , < any > Object . assign ( { } , config , { $type : 'ng2' } ) ) ;
119+ $view . viewConfigFactory ( 'ng1-to-ng2' , ( path : PathNode [ ] , config : Ng2ViewDeclaration ) => {
120+ var ng1ViewConfig : ViewConfig = < any > new Ng1ViewConfig ( < any > path , < any > Object . assign ( { } , config , { $type : 'ng1' } ) ) ;
121+ var ng2ViewConfig : ViewConfig = < any > new Ng2ViewConfig ( < any > path , < any > Object . assign ( { } , config , { $type : 'ng2' } ) ) ;
117122
118123 return [ ng2ViewConfig , ng1ViewConfig ] ;
119124 } ) ;
0 commit comments