Hello everyone,
i’ve fixed my old problem ([Solved] Ionic 3.6 - Problem with IonicPage url loading the wrong page) but by fixing that another problem came out.
When i refresh the page or copy and paste the link on a new tab, the page is loaded too fast, my variable are sitll not initialized so i get errors (while if i inspect the code and look at the var, they are ok since after the error the var are filled with the right value).
I think the problem is that IonicPage load before the app.component.ts (since i tryed to move the code of var inizialization before the platform ready and it didn’t work) so it fail to find filled variable…
I can’t even link my online test since online it works correctly, but locally it returns the errors…
Does anyone have the same issue? Have found any solution?
app.component.ts
import { Component, ViewChild } from '@angular/core';
import { Platform, Nav, AlertController, LoadingController } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import * as firebase from 'firebase';
import { AuthService } from '../providers/auth-service';
import { ChannelService } from '../providers/channel-service';
import { PushService } from '../providers/push-service';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
@ViewChild(Nav) nav: Nav;
rootPage: any;
loading: any;
constructor(platform: Platform, public authService: AuthService, public channelService: ChannelService, public pushService: PushService, public alertCtrl: AlertController, public loadingCtrl: LoadingController, public statusBar: StatusBar, public splashScreen: SplashScreen) {
firebase.initializeApp({});
let self = this;
platform.ready().then(() => {
const unsubscribe = firebase.auth().onAuthStateChanged((user) => {
if(user) {
firebase.database().ref('/users/' + user.uid).once('value').then((result) => {
authService.initializeUser(result.val(), result.getKey());
channelService.loadChannels();
self.rootPage = 'TabsPage';
unsubscribe();
});
} else {
self.rootPage = 'LoginPage';
unsubscribe();
}
});
if(platform.is('cordova')) {
statusBar.styleDefault();
splashScreen.hide();
pushService.initCordova();
} else {
pushService.initWeb();
}
});
}
}
new.ts
import { Component } from '@angular/core';
import { IonicPage, NavController, LoadingController } from 'ionic-angular';
import { AuthService } from '../../providers/auth-service';
@IonicPage({
priority: 'high',
segment: 'news',
})
@Component({
selector: 'page-news',
templateUrl: 'news.html'
})
export class NewsPage {
loading: any;
username = "";
constructor(public navCtrl: NavController, private authService: AuthService, private loadingCtrl: LoadingController) {
let info = this.authService.getUserInfo();
this.username = info.username;
}
}
news.module.ts
import { NgModule } from '@angular/core';
import { NewsPage} from './news';
import { IonicPageModule } from 'ionic-angular';
@NgModule({
declarations: [NewsPage],
imports: [IonicPageModule.forChild(NewsPage)],
entryComponents: [NewsPage]
})
export class NewsPageModule { }