Hey,
I’ve just started my journey with Ionic 2, and have been trying to learn passing paramters through modals. A few couple of posts and the docs cover the basics, but I’m trying to do something with a provider that I’ve been struggling with for 5 hours or so, and feeling stupid.
I’m trying to open a model from ‘Home’, which presents ‘Second’. On ‘Second’ there is a list, which the user selects an item from. ‘Second’ closes, and the selected item is shown on ‘Home’.
Alongside this, I’d like the parameter (description) from this selected item to be passes to a third modal, ‘Three’. Where ‘Three’ is opened also from ‘Home’, but shows the {{test.description}} from the selected list of ‘Second’. Here’s the attempt in code (removed all of the obvious stuff).
Home.html
...
<p *ngIf="test == 0" (click)=goToList>
Select an option<!-- {{test.id}} -->
</p>
<p *ngIf="data != 0">
{{test.id}}</p>
...
Home.ts
import { Data } from '../../providers/data';
...
constructor(public modalCtrl:ModalController, public navParams:NavParams, public data:Data) {
...
goToList(){
let modal = this.modalCtrl.create(SecondPage,Data);
modal.onDidDismiss((data: any[]) => {
this.data=data;
});
modal.present();
}
Second.html
<ion-item *ngFor="let test of tests" (click)="testSelect()">
{{test.id}}
</ion-item>
Second.ts
testSelect(){
this.viewCtrl.dismiss();
}
data.ts
data: any;
constructor() {
this.data = [{
"id": "one",
"desc": "this is a description "
}
];
}
loadData(){
return Promise.resolve(this.data)
}
Third.ts
?
Third.html
<p>{{test.description}}</p>
Thanks so much in advance for any help.