Thursday, May 16, 2019

how to pass data in ionic

how to pass data in ionic

Today i'm doing a example padding data in ionic, i use navController ionic this send data for
component to component other.
how to pass data in ionic

First you create an application for use with the following command, you can host the application in the folder easy to remember for to be able to work easily.
Install Ionic and Cordova
npm install -g ionic cordova
The command creates the application by cmd
ionic start demoPadding blank --type=angular
Change into the app folder, then push your code to ionic appflow.
cd demoPadding
Run the App
ionic serve
After i wil pass data to anoter page in ionic
Step 1. create page1
ionic generate page page1
page1.html
<ion-card *ngFor="let item of items" (click)="test($event, item)">
 Example pass data
</ion-card>
page1.ts
public test(event ,item ){
this.navCtrl.push(page2,{
item:item
});
}
Step 2. create page2
ionic generate page page2
page2.ts
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';

@IonicPage()
@Component({
  selector: 'page2',
  templateUrl: 'page2.html',
})
export class Page2 {
value:any;
constructor(public navCtrl: NavController, public navParams: NavParams) {
    this.value = navParams.get('item');
  }
  ionViewDidLoad() {
    console.log('ionViewDidLoad EmiCalPage');
  }

}
page2.html
<div>
{{value}}
</div>

No comments:

Post a Comment