Currently, I am in the process of working on a school project and facing an issue where I am trying to open a modal view from an action-sheet button. However, I encounter the following error message:
TypeError: Cannot read property 'addMedicationModalCtrl' of undefined
. Surprisingly, when I place the ion-button outside the action-sheet, it functions as expected.
Below is a snippet of the sample code that I am working with:
constructor(
private addMedicationModalCtrl: ModalController,
private actionSheetCtrl: ActionSheetController,
) { }
ngOnInit() {
}
addMedication() {
console.log("add medication");
this.addMedicationModalCtrl.create({
component: CreateMedicationComponent
}).then(modalEle => {
modalEle.present();
});
}
onTreatment() {
const actionSheet = this.actionSheetCtrl.create({
header: 'Treatment',
buttons: [
{
text: 'Medication',
role: 'medication',
handler: this.addMedication,
},
],
})
actionSheet.then(actionSheetEle => {
actionSheetEle.present();
});
}