how to pass data in ionic
Today i'm doing a example padding data in ionic, i use navController ionic this send data forcomponent to component other.
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 cordovaThe command creates the application by cmd
ionic start demoPadding blank --type=angularChange into the app folder, then push your code to ionic appflow.
cd demoPaddingRun the App
ionic serveAfter i wil pass data to anoter page in ionic
Step 1. create page1
ionic generate page page1page1.html
<ion-card *ngFor="let item of items" (click)="test($event, item)">Step 2. create page2
Example pass data
</ion-card>
page1.ts
public test(event ,item ){
this.navCtrl.push(page2,{
item:item
});
}
ionic generate page page2page2.ts
import { Component } from '@angular/core';page2.html
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');
}
}
<div>
{{value}}
</div>
No comments:
Post a Comment