Предыдущие данные navParam теряются после загрузки приложения в ionic3? - PullRequest
0 голосов
/ 06 января 2019

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 не отображается. Я не понимаю, почему. Проверьте мою скрипку и скажите, в чем причина этого?

1-й наш файл login.ts, в котором у нас есть страница и данные:

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

2-й - это наш файл 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);
    }
 } 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...