import { Injectable } from '@angular/core' ; import { Nav } from 'ionic-angular' ; import { PlaceholderPage } from '../../pages/placeholder/placeholder' ; import { _DetailPage } from '../../pages/_DetailPage' ; import { Subject } from "rxjs/Subject" ; /**
 * Service that handles view changes within master/detail components.
 */ @ Injectable ( ) export class NavProxyService { public selectedItem : Subject < string > = new Subject < string > ( ) ; _masterNav : Nav = null ; get masterNav ( ) : Nav { return this . _masterNav ; } set masterNav ( value ) { this . _masterNav = value ; } _detailNav : Nav = null ; get detailNav ( ) : Nav { return this . _detailNav ; } set detailNav ( value ) { this . _detailNav = value ; } _isOn : boolean = false ; get isOn ( ) : boolean { return this . _isOn ; } set isOn ( value ) { this . _isOn = value ; } pushDetail ( page , params ) { ( this . isOn ) ? this . detailNav . setRoot ( page , params ) : this . masterNav . push ( page , params ) ; } pushMaster ( page , params ) { this . masterNav . push ( page , params ) ; } popMaster ( params ) { this . masterNav . pop ( params ) ; } onSplitPaneChanged ( isOn ) { this . isOn = isOn ; if ( this . masterNav && this . detailNav ) { ( isOn ) ? this . activateSplitView ( ) : this . deactivateSplitView ( ) ; } } activateSplitView ( ) { let currentView = this . masterNav . getActive ( ) ; if ( currentView . component . prototype instanceof _DetailPage ) { this . masterNav . pop ( ) ; this . detailNav . setRoot ( currentView . component , currentView . data ) ; } } deactivateSplitView ( ) { let detailView = this . detailNav . getActive ( ) ; this . detailNav . setRoot ( PlaceholderPage ) ; if ( detailView . component . prototype instanceof _DetailPage ) { let index = this . masterNav . getViews ( ) . length ; this . masterNav . insert ( index , detailView . component , detailView . data ) ; } } }