【发布时间】:2021-01-15 13:58:03
【问题描述】:
我正在做一个学校项目,我想从操作表按钮打开一个模式视图,但我确实在下面收到此错误
TypeError: Cannot read property 'addMedicationModalCtrl' of undefined 但是当我在操作表外使用离子按钮时,它可以工作。
下面示例代码的快照
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();
});
}
【问题讨论】:
标签: angular typescript ionic-framework