Hi,
is there a way to return a value from a modal?
I have a modal with search component implemented selected value should be returned and modal closes, i have done the closing part but no idea how to get that value.
Did anyone done this?
Thanks
Hi,
is there a way to return a value from a modal?
I have a modal with search component implemented selected value should be returned and modal closes, i have done the closing part but no idea how to get that value.
Did anyone done this?
Thanks
If you save that value in the $scope it should stick even with the modal closed. Did you try?
can we use $scope in angular 2?
My bad, I didn’t notice you were talking about angular2. No idea then
Thanks Richard, i will definitely going to look into this.
You could always use a shared service to store data in, the solution Richard mentioned is probably better for most cases.
This will be added in the alpha.38 release which I plan on doing later today, you will be able to pass data back in the close function:
https://github.com/driftyco/ionic2/issues/668
In the close function of the modal page:
closeModal() {
this.close({
adel: 'hello',
lionel: 'hello'
});
}
In the function opening the modal from the main page:
openToolbarModal() {
this.modal.open(ToolbarModal).then(modalRef => {
// modal has finished opening
// modalRef is a reference to the modal instance
modalRef.onClose = (modalData) => {
// somehow modalRef.close(modalData) was called w/ modalData
console.log('modalRef.onClose', modalData)
}
});
}
https://github.com/driftyco/ionic2/blob/master/ionic/components/modal/test/basic/index.ts
When this is released I’ll be adding an example to the conference app, as well.
Up!
At now, I can return data throw dismiss method. But, I don’t understand how I can catch this data?
PS: Please. fix docs
Once you’ve created your modal, add an onDismiss
listener before presenting it on the nav, i.e:
myModal.onDismiss(data => {
console.log(data);
});
Please note that the method was renamed to onDidDismiss:
let profileModal = this.modalCtrl.create(Profile, { userId: 8675309 });
profileModal.onDidDismiss(data => {
console.log(data);
});
profileModal.present();