# Static get parameters() because navController in Service Provider

**URL:** <https://forum.ionicframework.com/t/static-get-parameters-because-navcontroller-in-service-provider/64428>\
**Category:** ionic-v3\
**Created:** [September 25, 2016, 4:17am UTC](https://forum.ionicframework.com/t/static-get-parameters-because-navcontroller-in-service-provider/64428 "2016-09-25T04:17:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![iludufre](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/iludufre/32/103517_2.png) [@iludufre](https://forum.ionicframework.com/u/iludufre)\
**Post date:** [September 25, 2016, 4:17am UTC](https://forum.ionicframework.com/t/static-get-parameters-because-navcontroller-in-service-provider/64428/1 "2016-09-25T04:17:33Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [September 25, 2016, 6:17am UTC](https://forum.ionicframework.com/t/static-get-parameters-because-navcontroller-in-service-provider/64428/2 "2016-09-25T06:17:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![iludufre](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/iludufre/32/103517_2.png) [@iludufre](https://forum.ionicframework.com/u/iludufre)\
**Post date:** [September 25, 2016, 3:10pm UTC](https://forum.ionicframework.com/t/static-get-parameters-because-navcontroller-in-service-provider/64428/3 "2016-09-25T15:10:42Z")

</div>

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.

Thanks.

[Edit]  
Found this: [https://forum.ionicframework.com/t/best-way-to-check-login-globally-in-ionic-2/49813](https://forum.ionicframework.com/t/best-way-to-check-login-globally-in-ionic-2/49813)

---

<div class="post-metadata">

**Author:** ![iludufre](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/iludufre/32/103517_2.png) [@iludufre](https://forum.ionicframework.com/u/iludufre)\
**Post date:** [September 25, 2016, 5:25pm UTC](https://forum.ionicframework.com/t/static-get-parameters-because-navcontroller-in-service-provider/64428/4 "2016-09-25T17:25:06Z")

</div>

It’s works. Thanks!

Added to app.ts:

```auto
    import { Events } from 'ionic-angular';

    constructor(private events: Events){ }

    this.events.subscribe('user:logout', () => {
      window.localStorage.clear();
      this.nav.setRoot(LoginPage).then(() => {
        this.alert.create({
          title: 'Ops!',
          subTitle: 'Please login.',
          buttons: ['OK']
        }).present();
      });
    });

```

And in Service Provider:

```auto
    import { Events } from 'ionic-angular';

    constructor(private events: Events){ }

    if(!this.isLogged){
      this.events.publish('user:logout');
    }

```
