Previous navParam data are lost after load app in ionic3?

Viewed 149

import { Component, ViewChild } from '@angular/core';
import { Nav, Platform, MenuController } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { Subject } from 'rxjs/Subject';

@Component({
templateUrl: 'app.html'
})
export class MyApp {
  @ViewChild(Nav) nav: Nav;
  userType : any = 'teacher';
  rootPage: any = 'WalkthroughPage';
  activePage = new Subject();

  pages: Array<{ title: string, component: any, active: boolean, icon: string }>;
  rightMenuItems: Array<{ icon: string, active: boolean }>;
  state: any;
  placeholder = 'assets/img/avatar/girl-avatar.png';
  chosenPicture: any;

constructor(
  public platform: Platform, 
  public statusBar: StatusBar,
  public splashscreen: SplashScreen,
  public menuCtrl: MenuController
) {
    this.initializeApp();
    this.rightMenuItems = [
    { icon: 'home', active: true },
    { icon: 'alarm', active: false },
    { icon: 'analytics', active: false },
    { icon: 'archive', active: false },
    { icon: 'basket', active: false },
    { icon: 'body', active: false },
    { icon: 'bookmarks', active: false },
    { icon: 'camera', active: false },
    { icon: 'beer', active: false },
    { icon: 'power', active: false },
    ];

    //here we will show sidemenu via userType wise....
    this.pages = [
      { title: 'Class Time Table', component: 'HomePage', active: true, icon: 'home' },
      { title: 'My Time Table', component: 'AccordionListPage', active: false, icon: 'map' },
      { title: 'Birthday',
        component: 'BirthdayPage', active: false, icon: 'ionic' },
      { title: 'Health Record', component: 'HealthRecordPage', active: false, icon: 'ionic' },
      { title: 'Curret Syllabus', component: 'SyllabusPage', active: false, icon: 'archive' },
      { title: 'About the School', component: 'ListPage', active: false, icon: 'body' },
      { title: 'Tearms & codition', component: 'ThemingPage', active: false, icon: 'power' },
      { title: 'Switch User', component: 'ThemingPage', active: false, icon: 'power' }
    ]
}

  this.activePage.subscribe((selectedPage: any) => {
      this.pages.map(page => {
       page.active = page.title === selectedPage.title;
    });
  });
}

initializeApp() {
  this.platform.ready().then(() => {
    this.statusBar.styleDefault();
    this.splashscreen.hide();
   this.menuCtrl.enable(false, 'right');
  });
}

openPage(page) {
  // Reset the content nav to have just this page
  // we wouldn't want the back button to show in this scenario
  this.nav.push(page.component);
  this.activePage.next(page);
}

rightMenuClick(item) {
  this.rightMenuItems.map(menuItem => menuItem.active = false);
  item.active = true;
}
}

I have creating the app in ionic which in which we have pass the userType from "login" screen to "dashboard" section 1st time value is get properly but if we have perfom any changes in the dashboard section after changes app is compile automactically now here in the navParam hold userType are not show i don't undetstand why.check my fiddle and tell me what is reason behind that?

1st our login.ts file in which we have push the page and data :

confirm() {
  this.navCtrl.setRoot('DashboardPage', {"type": this.type});
}

2nd is our dashboard.ts file in which we have get userType:

import { Component } from '@angular/core';import { IonicPage, NavController, NavParams } from 'ionic-angular'; 

@IonicPage()
@Component({  
  selector: 'page-dashboard',
  templateUrl: 'dashboard.html'
 })
  
  export class DashboardPage { 
    public type : any;
    constructor(
    public navCtrl: NavController,
    public navParams: NavParams) {
    
    this.type = this.navParams.get('type');
    console.log('type' +this.type);
    }
 } 

0 Answers
Related