Problem switching to TabsPage from SplashPage


#1

Hello, i’ve a problem. I tried to create a SplashScreen before my TabsPage since i want to sync with a Webserver and i dont want to use the Splashscreen Plugin.

Now i made the SplashPage as RootPage which is working fine.

In my SplashPage after the sync is done im forwarding to my TabsPage trying several ways

 this.nav.rootNav.setRoot(HomePage);
 this.nav.rootNav.push(HomePage);

or
this.nav.rootNav.setRoot(TabsPage);
this.nav.rootNav.push(TabsPage);
or
this.nav.setRoot(HomePage);
this.nav.push(HomePage);
or
this.nav.setRoot(TabsPage);
this.nav.push(TabsPage);

It doesnt matter what i try, it doesnt switch to the HomePage or the Tabs are missing or the Screen is Black.

If i set the TabsPage as RootPage in the app.ts then its working, but the SplashScreen is missing.

Is this a bug or am i doing something wrong?


#2

I just use
this.nav.setRoot(TabsPage)
without calling push after and it works.


#3

Thank you.

I figured out that almost all problems happen while using Promises.

If i do this.nav.setRoot() out of the Promise it works. But i have to wait until the Promise resolved. I cant use obserable in this case since SqlStorage doesnt provide Obserable. As soon as i use Promises like here, its bugged.

   this.syncService.sync().then(
        () => { this.nav.setRoot(TabsPage); }
    );

same with setting vars. If i use this.var =“bla” within the Promise its not “updating”. When i switch the Tab and go back then the data are updated. What may be wrong?


#4

Here’s a code of the push which is not working.

sync() {
var SyncDataObservable = Observable.fromPromise(this.sqlservice.storage.get("_syncdata"));

    SyncDataObservable.subscribe(
        (syncDate: number) => {
            console.log("observer got syncdata. ITs=" + syncDate);

            let body = { info: { lastSyncDate: (syncDate / 100000) } };
            let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
            let options = new RequestOptions({ headers: headers });

            return this.http.post(this.SYNCDATA.url, "data=" + JSON.stringify(body), options).map(((res: Response) => res.json()))
                .subscribe(httpdata => {
                    this.SYNCDATA.tableToSync.map(
                        (table) => {
                            console.log("syncing table " + table.tableName);
                            httpdata.data[table.tableName].map((k) => {
                                this.sqlservice.insertOrUpdateWithArgs(table.tableName, k, (table.uId != null) ? table.uId : null);
                            });
                        }
                    );

                    this.data.next("RESULT:OK");
                    return this.data.complete();
                });
        }
    )

}

and finally in splash

export class SplashPage {

constructor(public nav: NavController, public syncService: SyncService) {

    this.syncService.getSync.subscribe(
        (data: string) => {
            if (data === "RESULT:OK") {
                console.log("changing page since result OK", data);
                this.changeRoot();
            }

        }
    )
}

changeRoot() {
    this.nav.setRoot(TabsPage);
    this.nav.push(TabsPage);
}

}