I'm having an issue with my Ionic 2 app. I've so far built a list page of items, and each item there navigating to a detail page. At the detail page, you can edit and choose to save or cancel any changes. Save is working great.
The issue is onDidDismiss() function saving the data even when the close function doesn't/shouldn't pass the data back to the detail page. Here's the relevant code.
DETAILS.ts
openModal() {
let data = this.user;
let editDetailsModal = this.modalCtrl.create(EditDetailsModal, data);
editDetailsModal.onDidDismiss((data) => {
if (data) {
// this.saveItem(data);
console.log("Data =>", data)
}
//console.log("Data =>", data)
});
editDetailsModal.present();
}
saveItem(data) {
this.user.push(data);
}
EDITDETAILSMODAL.ts
saveModal() {
let data = this.user;
this.viewCtrl.dismiss(data);
//console.log(this.user)
}
close() {
this.viewCtrl.dismiss();
}
EditDetailsModal page has a form to edit the data passed to it. I'm sure I'm missing something simple. Even when calling an external save function, it just made a mess of the app. Happy to do a plunkr if this isn't enough information.
Ionic Info
Cordova CLI: 6.4.0
Ionic Framework Version: 3.0.1
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.3.0
ios-deploy version: 1.9.1
ios-sim version: 5.0.13
OS: macOS Sierra
Node Version: v6.9.5
Xcode version: Xcode 8.3.1 Build version 8E1000a