# Ionic 4: NavParams alternative

**URL:** <https://forum.ionicframework.com/t/ionic-4-navparams-alternative/136679>\
**Category:** Ionic Framework\
**Created:** [July 30, 2018, 3:03am UTC](https://forum.ionicframework.com/t/ionic-4-navparams-alternative/136679 "2018-07-30T03:03:20Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![hardikdg](https://avatars.discourse-cdn.com/v4/letter/h/9de053/32.png) [@hardikdg](https://forum.ionicframework.com/u/hardikdg)\
**Post date:** [July 30, 2018, 3:03am UTC](https://forum.ionicframework.com/t/ionic-4-navparams-alternative/136679/1 "2018-07-30T03:03:20Z")

</div>

In the Ionic 4, Ionic has removed the NavController and NavParams. So we can’t directly pass the JSON object between 2 pages.

So what can be the best way to send JSON object between 2 pages.

- One option is using services, but for every page, we need to create a custom set and get method for data passing.

So what is the best way to pass dynamic JSON object between different pages in Ionic 4 with the help of angular routing?

---

<div class="post-metadata">

**Author:** ![joshmorony](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/joshmorony/32/117695_2.png) [@joshmorony](https://forum.ionicframework.com/u/joshmorony)\
**Post date:** [July 30, 2018, 3:37am UTC](https://forum.ionicframework.com/t/ionic-4-navparams-alternative/136679/2 "2018-07-30T03:37:37Z")

</div>

Yes, you would use services. In general, you would do something like pass an `id` through the URL, which can be read by the activated route, and then you would use that `id` to look up the data you want in a service.

---

<div class="post-metadata">

**Author:** ![pradt](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/pradt/32/120744_2.png) [@pradt](https://forum.ionicframework.com/u/pradt)\
**Post date:** [August 1, 2018, 3:34am UTC](https://forum.ionicframework.com/t/ionic-4-navparams-alternative/136679/3 "2018-08-01T03:34:08Z")

</div>

NavController is still available in Ionic 4 but the signatures have changed (i.e push/pop is no longer there).

However, I normally use a singleton service as communication bus between pages which I found to be far more powerful than navParams (i.e I don’t need to pass similar context around various pages, i just need to set it once etc… ).

---

<div class="post-metadata">

**Author:** ![reedrichards](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@reedrichards](https://forum.ionicframework.com/u/reedrichards)\
**Post date:** [August 1, 2018, 5:31am UTC](https://forum.ionicframework.com/t/ionic-4-navparams-alternative/136679/4 "2018-08-01T05:31:32Z")

</div>

Providers for navigation  
NavParams for modals

---

<div class="post-metadata">

**Author:** ![salad-gg](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/salad-gg/32/135008_2.png) [@salad-gg](https://forum.ionicframework.com/u/salad-gg)\
**Post date:** [November 28, 2018, 8:49am UTC](https://forum.ionicframework.com/t/ionic-4-navparams-alternative/136679/5 "2018-11-28T08:49:24Z")

</div>

I am using ionic 4. It does not accept to receive data using navparams.  
Here is my **sender page** method:

```auto
  gotoFinalView(intent) {
    this.route.navigateByUrl(`${intent}`, this.destination);
  }

```

**Receiver page line;**

`this.item = navParams.data;`

What is the right approach to doing this in ionic 4. I am also uncertain about the validity of the method I have created in the sender page.

---

<div class="post-metadata">

**Author:** ![salad-gg](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/salad-gg/32/135008_2.png) [@salad-gg](https://forum.ionicframework.com/u/salad-gg)\
**Post date:** [November 30, 2018, 7:16am UTC](https://forum.ionicframework.com/t/ionic-4-navparams-alternative/136679/6 "2018-11-30T07:16:04Z")

</div>

This is how I solved my problem:  
**I created a Service with a setter and getter methods as;**

```auto
import { Injectable } from "@angular/core";

@Injectable({
  providedIn: "root"
})
export class MasterDetailService {
  private destn: any;
  constructor() {}

  public setDestn(destn) {
    this.destn = destn;
  }

  getDestn() {
    return this.destn;
  }
}

```

**Injected the Service and NavController in the first page and used it as;**

```auto
  gotoFinalView(destn) {
    this.masterDetailService.setDestn(destn);
    this.navCtrl.navigateForward("destn-page");
  }

```

**Extracted the data at the final page by;**

```auto
constructor(
    private masterDetailService: MasterDetailService
  ) {
    this.destination = this.masterDetailService.getDestn();
  }

```

---

<div class="post-metadata">

**Author:** ![ricardorick45](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@ricardorick45](https://forum.ionicframework.com/u/ricardorick45)\
**Post date:** [July 17, 2019, 4:21am UTC](https://forum.ionicframework.com/t/ionic-4-navparams-alternative/136679/7 "2019-07-17T04:21:27Z")

</div>

Resolveu meu problema

---

<div class="post-metadata">

**Author:** ![AlGantori](https://avatars.discourse-cdn.com/v4/letter/a/35a633/32.png) [@AlGantori](https://forum.ionicframework.com/u/AlGantori)\
**Post date:** [April 24, 2020, 12:21pm UTC](https://forum.ionicframework.com/t/ionic-4-navparams-alternative/136679/8 "2020-04-24T12:21:53Z")

</div>

is **this.ViewController.data** injected in the component also gone in Ionic4 ?

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:01pm UTC](https://forum.ionicframework.com/t/ionic-4-navparams-alternative/136679/9 "2021-07-19T21:01:08Z")

</div>

Closed on July 19, 2021, 9:01pm UTC


