Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70890

[Must be a Bug?]Switching from Subscribtion to Page not working

$
0
0

@seiboldsoft wrote:

Dear Ionic Team,

im pretty sure i tried everything possible to get this working.

I've a service which returns an observable. Onec the Observable send an event, it should change the page. I get the log that the event received and "Chaning page since result OK". But when it hits the setRoot() it doesnt work.

The Annoying thing is, that sometimes its moving after a long time (timeout)?
Here's a part of my code:

app.ts

  constructor(private menu: MenuController, private app: IonicApp, private platform: Platform, public syncService: SyncService) {

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

            }
        )
}

changeRoot() {
let nav = this.app.getComponent('nav');
nav.setRoot(TabsPage);
nav.push(TabsPage);
}

and a part of the sync-service.ts


get getSync() {    return this.asObservable(this.data);   }
asObservable(subject: Subject<any>) {   return new Observable(fn => subject.subscribe(fn));   }


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

The event changing page since result OK is called. WebDevelopers Console doesnt show any error. even when surrounding with try catch.

Edit: In log i get "finish loading tabs.html" which means that the switching works but hte view is not updated.

Posts: 4

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 70890

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>