I'm quite new to Ionic 2 development and would like your help. Does anyone know how what event es after onDidDismiss() ?
presentProfileModal() {
let profileModal = this.modalCtrl.create(Profile, { userId: 8675309 });
profileModal.onDidDismiss(data => {
console.log(data);
});
profileModal.present();
}
I would know how to store the parameter to parent's properties after onDidDismiss()
from a modal page.
Edited:
So this is my actual codes which I can't solve. While debugging using vs2015, the parent ponent appears undefined after I am calling this.viewCtrl.dismiss(this.calibration)
and my breakpoint was in onDidDismiss() event. Inside data
has values but I can't store the results to the parent ponent.
[Parent Component Undefined Error Image][1]
[1]: .png
This is the code to create my modal:
public goToCalibration(calibration, seqNo) {
this.selectedCalibrationTask = seqNo;
let modal = this.modalCtrl.create(ModalCalibrationPage, { "calibration": calibration });
modal.onDidDismiss(data => {
this.value = data;
//for (var i = 1; i < this.task.TaskItems.length; i++) {
// if (this.task.TaskItems[i].SeqNo == this.selectedCalibrationTask) {
// if (data != null) {
// this.task.TaskItems[i].Calibration = data;
// }
// break;
// }
//}
});
modal.present();
}
Modal TS code:
export class ModalCalibrationPage {
public calibration: any;
public constructor(public viewCtrl: ViewController, private navParams: NavParams) {
if (this.navParams.get("calibration") != null) {
this.calibration = this.navParams.get("calibration");
}
else {
this.calibration = {
EquipmentBefore: '',
InstrumentBefore: '',
ControlRoomBefore: '',
EquipmentAfter: '',
InstrumentAfter: '',
ControlRoomAfter: '',
StandardSignal: {
Std1: '',
Std2: '',
Std3: '',
Error1: '',
Error2: '',
Error3: ''
},
BeforeCalibration: {
Std1: '',
Std2: '',
Std3: '',
Error1: '',
Error2: '',
Error3: ''
},
AfterCalibration: {
Std1: '',
Std2: '',
Std3: '',
Error1: '',
Error2: '',
Error3: ''
},
MeasuredVoltage: '',
StandardType: '',
UOM: '',
InstrumentAccuracy: '',
InstrumentCalibrated: false,
Remarks: ''
};
}
}
public dismiss() {
this.viewCtrl.dismiss();
}
public saveCalibration() {
this.viewCtrl.dismiss(this.calibration);
}
}
I'm quite new to Ionic 2 development and would like your help. Does anyone know how what event es after onDidDismiss() ?
presentProfileModal() {
let profileModal = this.modalCtrl.create(Profile, { userId: 8675309 });
profileModal.onDidDismiss(data => {
console.log(data);
});
profileModal.present();
}
I would know how to store the parameter to parent's properties after onDidDismiss()
from a modal page.
Edited:
So this is my actual codes which I can't solve. While debugging using vs2015, the parent ponent appears undefined after I am calling this.viewCtrl.dismiss(this.calibration)
and my breakpoint was in onDidDismiss() event. Inside data
has values but I can't store the results to the parent ponent.
[Parent Component Undefined Error Image][1]
[1]: https://i.sstatic/12TVj.png
This is the code to create my modal:
public goToCalibration(calibration, seqNo) {
this.selectedCalibrationTask = seqNo;
let modal = this.modalCtrl.create(ModalCalibrationPage, { "calibration": calibration });
modal.onDidDismiss(data => {
this.value = data;
//for (var i = 1; i < this.task.TaskItems.length; i++) {
// if (this.task.TaskItems[i].SeqNo == this.selectedCalibrationTask) {
// if (data != null) {
// this.task.TaskItems[i].Calibration = data;
// }
// break;
// }
//}
});
modal.present();
}
Modal TS code:
export class ModalCalibrationPage {
public calibration: any;
public constructor(public viewCtrl: ViewController, private navParams: NavParams) {
if (this.navParams.get("calibration") != null) {
this.calibration = this.navParams.get("calibration");
}
else {
this.calibration = {
EquipmentBefore: '',
InstrumentBefore: '',
ControlRoomBefore: '',
EquipmentAfter: '',
InstrumentAfter: '',
ControlRoomAfter: '',
StandardSignal: {
Std1: '',
Std2: '',
Std3: '',
Error1: '',
Error2: '',
Error3: ''
},
BeforeCalibration: {
Std1: '',
Std2: '',
Std3: '',
Error1: '',
Error2: '',
Error3: ''
},
AfterCalibration: {
Std1: '',
Std2: '',
Std3: '',
Error1: '',
Error2: '',
Error3: ''
},
MeasuredVoltage: '',
StandardType: '',
UOM: '',
InstrumentAccuracy: '',
InstrumentCalibrated: false,
Remarks: ''
};
}
}
public dismiss() {
this.viewCtrl.dismiss();
}
public saveCalibration() {
this.viewCtrl.dismiss(this.calibration);
}
}
Share
Improve this question
edited Nov 2, 2020 at 9:30
peterh
1
asked May 2, 2017 at 7:59
Irving LeeIrving Lee
1351 gold badge2 silver badges12 bronze badges
6
- Data has values but i can store the results to the parent ponent. do you mean it returns actual values but it is not getting set or undefined is returned? – Suraj Rao Commented May 2, 2017 at 9:20
- Sorry there was a typo "but i can't store" – Irving Lee Commented May 2, 2017 at 9:25
- and yes it returns actual values input by users but its not getting set. – Irving Lee Commented May 2, 2017 at 9:26
-
I think you are simply checking this.value too early.. why not just console log it?
console.log(JSON.stringify(this.value,undefined,2))
– Suraj Rao Commented May 2, 2017 at 9:30 - All right i will check it thanks Suraj. – Irving Lee Commented May 2, 2017 at 9:34
2 Answers
Reset to default 4If I understand correctly, you want to set data
in parent ponent.
You should have a class property in the parent and set within the data value within onDidDismiss()
callback.
value:any;
presentProfileModal() {
let profileModal = this.modalCtrl.create(Profile, { userId: 8675309 });
profileModal.onDidDismiss(data => {
console.log(data);
this.value=data;//here
console.log(JSON.stringify(this.value,undefined,2));
});
profileModal.present();
}
In the modal you send in ViewController's dismiss()
function.
this.viewCtrl.dismiss(data)
This is what my answer is after applying suraj solution. I only could assign the results to the parent ponent after onDidDismiss()
event and not manipulate any data. So i hope this could help someone who face the same issue as me.
Parent's TS Code:
public selectedCalibrationTask: any;
public selectedSeqNo: any;
public goToCalibration(seqNo) {
if (this.selectedSeqNo == null)
{
this.selectedSeqNo = seqNo;
}
let modal = this.modalCtrl.create(ModalCalibrationPage, { "calibration": this.selectedCalibrationTask, "seqNo": this.selectedSeqNo });
modal.onDidDismiss(data => {
this.selectedCalibrationTask = data.calibration;
});
modal.present();
}
Modal's TS Code:
public saveCalibration() {
this.viewCtrl.dismiss(this.calibration);
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744868024a4598090.html
评论列表(0条)