import { Component , ViewChild } from "@angular/core" ; import { Router } from "@angular/router" ; import { CommBroker , IMessage } from "../../services/CommBroker" ; import { Consts } from "../../../src/Conts" ; import TodoStatsModel from "./todos/TodoStatsModel" ; import { TodoService } from "./todos/TodoService" ; import { ModalDirective } from "ng2-bootstrap" ; @ Component ( { providers : [ TodoStatsModel , TodoService ] , templateUrl : './App1.html' } ) export class App1 { private routerActive : boolean ; private unsub1 ; private unsub2 ; private loading : boolean = false ; constructor ( private commBroker , private router ) { this . listenMenuChanges ( ) ; router . navigate ( [ '/App1/Todos' ] ) ; } ngOnInit ( ) { this . routerActive = true ; this . commBroker . getService ( Consts . Services ( ) . App ) . appResized ( ) ; } /** Examples on router life-cycle hooks **/ @ ViewChild ( 'lgModal' ) public lgModal : ModalDirective ; public listenMenuChanges ( ) { var self = this ; this . unsub1 = self . commBroker . onEvent ( Consts . Events ( ) . LAZYLOAD_COMPLETED ) . subscribe ( ( e ) => { this . lgModal . hide ( ) ; } ) ; this . unsub2 = self . commBroker . onEvent ( Consts . Events ( ) . MENU_SELECTION ) . subscribe ( ( e ) => { if ( ! self . routerActive ) return ; let screen = ( e . message ) ; if ( screen == 'LazyLoad' ) if ( ! this . loading ) { this . loading = true ; } self . router . navigate ( [ `/App1/${ screen }` ] ) ; } ) ; } ngOnDestroy ( ) { this . unsub1 . unsubscribe ( ) ; this . unsub2 . unsubscribe ( ) ; } }