How to pass data between tabs in Ionic
There are several way you could achieve this.
Events
would be the right choice when it comes to passing data between different pages.Events is a publish-subscribe style event system for sending and responding to application-level events across your app.
create an event with
constructor(public events: Events) {} function sendData(data) { events.publish('data:created', data); }
subscribe to it using
events.subscribe('data:created', (data) => { console.log( data); });
Use a shared service
constructor(public shared: Share) {} pushData(data){ this.shared.items.push(data); }
You can access
items
in other components usingthis.shared.items
when you inject the service globally inapp.module.ts
- Another option would be to use
segments
instead oftabs
. This depends on the use case. For simple applications, this would be the better solution. You can learn more from the documentation.
Edit
I have avoided storing the data in database as its not an efficient way to do this. But there may be use cases for such an approach.