在ionic3中加载应用后,先前的navParam数据会丢失吗?

时间:2019-01-06 10:54:00

标签: ionic3

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;
}
}

我已经在ionic中创建了应用程序,在该应用程序中,我们已将userType从“登录”屏幕传递到“仪表板”部分,第一次值是正确的,但是如果我们在更改应用程序编译后对仪表板部分进行了更改,现在在navParam中,在这里自动地保持userType不会显示我不理解为什么。请检查我的小提琴并告诉我其背后的原因是什么?

第一个我们的login.ts文件,其中已推送页面和数据:

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

2nd是我们的dashboard.ts文件,在其中获得了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 个答案:

没有答案