In Ionic 3 you could use the second argument of the navController to pass data to the next page and retrieve it with the navParams service.
This was a really convenient feature. Is there an equivalent api for routing in Ionic 4?
You can always JSON.stringify the object/array to the routerParams, which in my opinion is less convenient.
In Ionic 4 you can pass data with the modalController using ComponentProps and @Input() making it more suitable of a quick push/pop implementation.
EDIT
My intention with this question is to find out if there are any native APIs from Angular 6+ or Ionic 4+. I am well aware of ways to implement a custom service or resolver to accomplish this.
The goal is to use ionic's and angular's api to its fullest, since in larger projects each custom code requires documentation and increases complexity.
You can simply pass the object with route using queryParams.
To receive this object you need to use ActivatedRoute which is to be imported from '@angular/router'
In case you have little complex structure of object.
let suppose you have below object to send.
To send the above object you need to first stringify the object with the help of JSON.stringfy().
To recieve this object you need to parse this object using JSON.parse() method.
I've been working with Ionic 4 since the first beta and I haven't found what you are looking for. I believe the Ionic team wants to leave the task of component interaction to the component framework (Angular, React, Vue...).
If you want to reduce complexity, you could use Angular services, redux or ngrx for state management of the application. This way you could navigate to a view, update the global state through an action, then go back to the previous view and show the updated state.
I have solved this
You can simply pass the object data with route using JSON.stringify.
To recieve this object you need to parse this object using JSON.parse() method.
to visualize the data we attach the name of the field where it is saved
you must first define the parameter in app.routing.module.ts
I hope it helps you, it really is the easiest way to do it
I have solved this by wrapping the Ionic NavController in a provider which has functions to set a value to a variable and a function to get it again. Similar to
this.navParams.get('myItem')
.Take a look at the following;
Hope this helps!
Actually there is many way to pass data between pages. I tried over
Route
andnavCtrl
but, it didn't works for me. I am sharing a way to pass data usingSERVICE
.this works for me.
There is multiple ways to pass a parameters from a page to another in Ionic v4 / Angular 7.2+:
1. Using Extras State (new since Angular 7.2) - Recommanded
Simple and clean
2. Use a service and a resolver
Does not fecth the data but a bit heavy.
Store the data into a service and pass a resolver using the router
3. Using object's id (not recommanded)
If your object is stored, you can pass the id in the url and fetch it again.
It will slows the application, implies that the object is stored somewhere and may increase networks issues (if not stored localy)
4. Using query params (not recommanded)
By stringyfing your object: See @Tahseen Quraishi's answer
Only few informations can be passed and the URL is hideous
Some examples here