import * as angular from 'angular' ; import { Component , NgModule , NgZone } from '@angular/core' ; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic' ; import { UpgradeModule } from '@angular/upgrade/static' ; import { BrowserModule } from '@angular/platform-browser' ; import { UIRouterUpgradeModule , NgHybridStateDeclaration } from '@uirouter/angular-hybrid' ; import { UrlService } from '@uirouter/core' ; const app = angular . module ( 'minimal' , [ 'ui.router.upgrade' ] ) ; app . run ( [ '$stateRegistry' , '$urlService' , ( $stateRegistry , $urlService ) => { $urlService . rules . initial ( { state : 'app' } ) ; $stateRegistry . register ( { url : '' , name : 'app' , template : `
        <a ui-sref=".ng1" ui-sref-active-eq="active">app.ng1</a>
        <a ui-sref=".ng1.ng2" ui-sref-active-eq="active">app.ng1.ng2</a>
        <a ui-sref=".ng2" ui-sref-active-eq="active">app.ng2</a>
        <a ui-sref=".ng2.ng2" ui-sref-active-eq="active">app.ng2.ng2</a>
        <ui-view></ui-view>
      ` , } ) ; $stateRegistry . register ( { url : '/ng1' , name : 'app.ng1' , component : 'ng1Component' , } ) ; $stateRegistry . register ( { url : '/ng2' , name : 'app.ng1.ng2' , component : Ng2Component , } ) ; $stateRegistry . register ( { url : '/ng2' , name : 'app.ng2' , component : Ng2Component , } ) ; } , ] ) ; app . component ( 'ng1Component' , { template : `
      <h1>ng1 component</h1>
      <a ui-sref="app">Back to app</a>
      <ui-view></ui-view>
    ` , controller : function ( ) { this . $onInit = function ( ) { console . log ( 'ng1Component.$onInit()' ) ; } ; } , } ) ; @ Component ( { selector : 'ng2-component' , template : `
    <h1>ng2 component</h1>
    <a uiSref="app">Back to app</a>
    <ui-view></ui-view>
  ` , } ) export class Ng2Component { ngOnInit ( ) { console . log ( 'Ng2Component.ngOnInit()' ) ; } } const nestedState = { url : '/ng2' , name : 'app.ng2.ng2' , component : Ng2Component , } ; @ NgModule ( { imports : [ BrowserModule , UpgradeModule , UIRouterUpgradeModule . forRoot ( { states : [ nestedState ] } ) , ] , declarations : [ Ng2Component ] , entryComponents : [ Ng2Component ] , } ) export class RootModule { constructor ( private upgrade ) { } ngDoBootstrap ( ) { this . upgrade . bootstrap ( document . body , [ app . name ] ) ; } } app . config ( [ '$urlServiceProvider' , ( $urlService ) => $urlService . deferIntercept ( ) ] ) ; platformBrowserDynamic ( ) . bootstrapModule ( RootModule ) . then ( ( platformRef ) => { const url = platformRef . injector . get ( UrlService ) ; function startUIRouter ( ) { url . listen ( ) ; url . sync ( ) ; } const ngZone = platformRef . injector . get ( NgZone ) ; ngZone . run ( startUIRouter ) ; } ) ;