passing data from one page to another in ionic 4

Solutions on MaxInterview for passing data from one page to another in ionic 4 by the best coders in the world

showing results for - "passing data from one page to another in ionic 4"
Alec
26 Jan 2018
1import { Component, OnInit } from '@angular/core';
2import { ActivatedRoute, Router } from '@angular/router';
3 
4@Component({
5  selector: 'app-details',
6  templateUrl: './details.page.html',
7  styleUrls: ['./details.page.scss'],
8})
9export class DetailsPage implements OnInit {
10 
11  data: any;
12 
13  constructor(private route: ActivatedRoute, private router: Router) {
14    this.route.queryParams.subscribe(params => {
15      if (this.router.getCurrentNavigation().extras.state) {
16        this.data = this.router.getCurrentNavigation().extras.state.user;
17      }
18    });
19  }
20 
21  ngOnInit() { }
22}
23
Karim
19 Apr 2016
1import { Component } from '@angular/core';
2import { Router, NavigationExtras } from '@angular/router';
3import { DataService } from '../services/data.service';
4 
5@Component({
6  selector: 'app-home',
7  templateUrl: 'home.page.html',
8  styleUrls: ['home.page.scss'],
9})
10export class HomePage {
11 
12  user = {
13    name: 'Simon Grimm',
14    website: 'www.ionicacademy.com',
15    address: {
16      zip: 48149,
17      city: 'Muenster',
18      country: 'DE'
19    },
20    interests: [
21      'Ionic', 'Angular', 'YouTube', 'Sports'
22    ]
23  };
24 
25  constructor(private router: Router, private dataService: DataService) { }
26 
27  openDetailsWithState() {
28    let navigationExtras: NavigationExtras = {
29      state: {
30        user: this.user
31      }
32    };
33    this.router.navigate(['details'], navigationExtras);
34  }
35}
36
Leona
28 Jan 2019
1import { DataResolverService } from './resolver/data-resolver.service';
2import { NgModule } from '@angular/core';
3import { Routes, RouterModule } from '@angular/router';
4 
5const routes: Routes = [
6  { path: '', redirectTo: 'home', pathMatch: 'full' },
7  { path: 'home', loadChildren: './home/home.module#HomePageModule' },
8  { path: 'details', loadChildren: './details/details.module#DetailsPageModule' },
9  {
10    path: 'details/:id',
11    resolve: {
12      special: DataResolverService
13    },
14    loadChildren: './details/details.module#DetailsPageModule'
15  }
16];
17 
18@NgModule({
19  imports: [RouterModule.forRoot(routes)],
20  exports: [RouterModule]
21})
22export class AppRoutingModule { }
23
Leah
01 Jan 2017
1ionic start academyNavigation blank --type=angular
2cd academyNavigation
3ionic g page details
4
Ashley
09 Oct 2018
1ionic g service services/data
2ionic g service resolver/dataResolver
3
Jeannette
19 Jul 2018
1<ion-header>
2  <ion-toolbar>
3    <ion-buttons slot="start">
4      <ion-back-button defaultHref="/"></ion-back-button>
5    </ion-buttons>
6    <ion-title>Details</ion-title>
7  </ion-toolbar>
8</ion-header>
9 
10<ion-content padding>
11<ion-card *ngIf="data">
12  <ion-card-header>
13    <ion-card-title>
14      {{ data.name }}
15    </ion-card-title>
16    <ion-card-subtitle>
17        {{ data.website }}
18    </ion-card-subtitle>
19  </ion-card-header>
20  <ion-card-content>
21    <ion-item *ngFor="let i of data.interests">
22      {{ i }}
23    </ion-item>
24  </ion-card-content>
25</ion-card>
26</ion-content>
27
Sofie
04 Nov 2016
1import { Component } from '@angular/core';
2import { Router } from '@angular/router';
3import { DataService } from '../services/data.service';
4 
5@Component({
6  selector: 'app-home',
7  templateUrl: 'home.page.html',
8  styleUrls: ['home.page.scss'],
9})
10export class HomePage {
11 
12  user = {
13    name: 'Simon Grimm',
14    website: 'www.ionicacademy.com',
15    address: {
16      zip: 48149,
17      city: 'Muenster',
18      country: 'DE'
19    },
20    interests: [
21      'Ionic', 'Angular', 'YouTube', 'Sports'
22    ]
23  };
24 
25  constructor(private router: Router, private dataService: DataService) { }
26 
27  openDetailsWithService() {
28    this.dataService.setData(42, this.user);
29    this.router.navigateByUrl('/details/42');
30  }
31}
32
Arwin
01 Jan 2019
1import { Component } from '@angular/core';
2import { Router } from '@angular/router';
3 
4@Component({
5  selector: 'app-home',
6  templateUrl: 'home.page.html',
7  styleUrls: ['home.page.scss'],
8})
9export class HomePage {
10 
11  user = {
12    name: 'Simon Grimm',
13    website: 'www.ionicacademy.com',
14    address: {
15      zip: 48149,
16      city: 'Muenster',
17      country: 'DE'
18    },
19    interests: [
20      'Ionic', 'Angular', 'YouTube', 'Sports'
21    ]
22  };
23 
24  constructor(private router: Router) { }
25 
26  openDetailsWithQueryParams() {
27    let navigationExtras: NavigationExtras = {
28      queryParams: {
29        special: JSON.stringify(this.user)
30      }
31    };
32    this.router.navigate(['details'], navigationExtras);
33  }
34}
35
Nicolás
10 Feb 2017
1import { Injectable } from '@angular/core';
2 
3@Injectable({
4  providedIn: 'root'
5})
6export class DataService {
7 
8  private data = [];
9 
10  constructor() { }
11 
12  setData(id, data) {
13    this.data[id] = data;
14  }
15 
16  getData(id) {
17    return this.data[id];
18  }
19}
20
Swan
31 Feb 2019
1import { DataService } from './../services/data.service';
2import { Injectable } from '@angular/core';
3import { Resolve, ActivatedRouteSnapshot } from '@angular/router';
4 
5@Injectable({
6  providedIn: 'root'
7})
8export class DataResolverService implements Resolve<any> {
9 
10  constructor(private dataService: DataService) { }
11 
12  resolve(route: ActivatedRouteSnapshot) {
13    let id = route.paramMap.get('id');
14    return this.dataService.getData(id);
15  }
16}
17
queries leading to this page
how to pass data from ionic page to another pageionic 3 pass data between pageshow to pass value from one page to another using ionic 5passing data between pages ionicionic navigate to page with datahow to pass data between ionic pagespass data from 1 page to another in ionicionic 4 redirect to another page with parametershow to pass data from one page to another page in ionicionic 5 pass data between pageshow to call a function from other page in ionichow to pass data from 1 page to another using navigation in ionic 4send decimal value in navigateforwardhow to send data in a variable from one page to another page in ionic 4how to send data form one page to another in ionicsend data with route ionic 5ionic 5 pass data to pagehow to pass data from one page to another in ionic 4first parameter passed then second parameter ionichow to pass data from one view to another 3f 3aionicionic 4 pass data to pageionic pass data to routehow to send data from one component to another in ionic 5passing data from one page to another in ionic 3sending id through route in ionic 5page navigation with parameter in ionic 5list of all possible ways to pass data in ionic 4 with examplesionic navigate to page with argumenthow to send entire object to one page in ioichow to pass data between pages in ionic 4how to pass data from ionic page to anotherhow to send object in url in ionic routesionic 5 not passing data between pageshow to pass data from one page to another in ionic 5passing data from one page to another in ionic 4passing parameters in ionic 4pass data between pages using router in ionic explainedhow to pass data from one page to another page in ionic 4ionic put data in routeionic send data to another page andoid ionic 5 pass value from service to pageionic pass data from one page to anotherpage navigation with paramter in ionic 5pass data from one html to another in ionichow to send variable data from one page to another in ionicpass data from one page to another in ionic 5passing data from one component to another in ionic4how to pass data from one page to another page in ionic 5how to send data from one component to another in ionicionic 4 pass data to another pagenavigationextras ionicionic router navigate with paramshow to pass data to another page in ionic 3parameter page ionicionic 4 send data between pageshow to call a function from another page in ionicionic redirect to another page with paramsangular ionic passing datapass data between pages ionicpass data between pages using router in ionicsend param component ionic 5pass elements from one page to another ionichow to navigate fom one page to another by passing data using ionic 4pass parameter in ionic 4how to pass parameters to page ionicpass data between pages ionic 5ionic send data to another pagepass data between pages in ionic 4how to ionic 5 pass object to another pagepass parameters ionic 5 pass data router ionicdifferent ways to transfer data between ionic pages namely and descriptionpass value from one page to another in ionic 4how to pass data from a page to another in ionicionic 4 pass data between pagessending data from one component to another in ionic 5data pass to another page ionichow to pass variable from one page to another in ionicionic send to another pageionic navigation with parametersionic go to another page with paramshow to save data to another page in ionic 5how to navigate fom one page to another by passing datapassing data between pages ionic 4send data from one page to another in ionic 4how to send data fom one page to another in ionichow to pass data from a page to another in ionic using routerionic how to pass data to another pagepass data from one page to another in ionichow to send parameter when navigate backward in ionic 4ionic 4 how to pass data between pageshow to take array data to other page in ionic angularionic pass data between pagespass data from a page to another ionic 5ionic 4 passing data between pageshow to pass data from 1 page to another using navigation in ionic 4 3fdynamically id passing one page to another page in ionic 5get data from one page to another in ionic angularionic router pass datanavigateforward pass parametershow to ionic 5 navigate forward with objecthow to pass value from one page to another using ionichow to send entire object data through navigation from one page to another site 3aforum ionicframework comhow to pass the while navigation in ionic 5send data to different page ionichow to transfer data between ionic pages using router examplespass data one page to another in ionicpass data to next page ionicionic send data to another page routerhow to pass data from one component to another in ionic 5 e2 80 9chow to pass data to another page in ionic 3 e2 80 9dionic router navigate with datahow to pass data to another page in ionic 5pass data from router to navigaterootpass data from one page to another ionicpassing data from one page to another in angular 11 ionic 5how to pass data to another page in ionic 4passing data from one page to another in ionic 4