gpt4 book ai didi

javascript - ionic 中 onTap 和 popUp 上 'this' 的范围是 'undefined'

转载 作者:行者123 更新时间:2023-12-03 06:46:55 25 4
gpt4 key购买 nike

我想在 ionic 中显示一个弹出窗口,它不允许用户在未输入某些输入时退出。现在我在这里使用这个:

public showOwnIdentifierPrompt() {
// Prompt popup code
var promptPopup = this.$ionicPopup.prompt({
title: this.floor_name,
template: `<input ng-model="$ctrl.customFloorName"></input>`,
scope: this.$scope,
buttons: [
{
text: this.cancel,
type: 'button-clear button-balanced',
onTap: function(e) {
// Cancel creation
return false;
}
},
{
text: this.save,
type: 'button-clear button-balanced',
onTap: () => {
// Create new floor
return true;
}
}
]
});

promptPopup.then((res) => {
if (res) {
this.addNewFloor(this.customFloorName);
}
})
}

在 save onTap() 事件处理程序中,我想从我的类访问 this.customFloorName ,以确定用户是否输入了内容。但它始终是未定义的。我能做些什么?

最佳答案

您可以使用以下代码在“保存”中获取值(value):

 var value = this.scope.$ctrl.customFloorName;

关于javascript - ionic 中 onTap 和 popUp 上 'this' 的范围是 'undefined',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37696886/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com