angular - 从操作表按钮打开模态视图不起作用
问题描述
我正在做一个学校项目,我想从操作表按钮打开一个模式视图,但我确实在下面收到此错误,
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();
});
}
解决方案
请稍微更改您的操作表处理程序函数。它会开始为你工作
onTreatment() {
const actionSheet = this.actionSheetCtrl.create({
header: 'Treatment',
buttons: [
{
text: 'Medication',
role: 'medication',
handler: () => {
this.addMedication()
},
},
],
})
actionSheet.then(actionSheetEle => {
actionSheetEle.present();
});
}
推荐阅读
- c# - Enterprise Architect UML 图,类模型
- javascript - 即使使用必需的属性,HTML 文本输入正则表达式验证也不起作用
- react-native - 反应原生选择器,获取选定的选项文本
- git - 如何将最后一个分支与主分支合并
- html - chrome mobile的设备宽度问题
- arrays - 使用 perl 在一个文件中的列查找另一个文件中的匹配列时出现定义错误
- sql - 如何在 SQL 中创建方阵表?
- android - 无法实例化 FloatingActionButton 类
- html - 使同一个 div 独立运行
- selenium - Сhromedriver:如何添加对基于 Chromium 的浏览器的支持