Static get parameters() because navController in Service Provider

Hi, my name is Luan and I have a problem.

I’ve added the NavController in my Service Provider, because I want set Root to Login Page depending of API return.

So, I added import { NavController, App } from 'ionic-angular';, private app: App in constructo and this.nav = app.getActiveNav();.

But now, I need to add static get parameters() { return [[NavController], ..., ... [ApiProvider]]; } in all Pages.

Exists any solution?

In my opinion, this is a design mistake. Services should not be dealing with the view layer. Expose an event emitter or an observable in the service, subscribe to it in a component controller, and set the root page appropriately there.

1 Like

I agree with you, is a design mistake. But, just because I started with Ionic in less than three week.
You can not imagine how much I took to understand the Promises, hahaha.

I’ll find out about events and how to call them when I need to.


Found this:

It’s works. Thanks!

Added to app.ts:

    import { Events } from 'ionic-angular';

    constructor(private events: Events){ }'user:logout', () => {
      this.nav.setRoot(LoginPage).then(() => {
          title: 'Ops!',
          subTitle: 'Please login.',
          buttons: ['OK']

And in Service Provider:

    import { Events } from 'ionic-angular';

    constructor(private events: Events){ }

1 Like