angular - 无法将重点放在提示警报输入上
问题描述
使用 Ionic 3,我创建了一个由函数触发的提示警报resetPassword()
。我希望它的唯一输入被聚焦并在显示时打开 iOS / Android 键盘。
这是功能:
resetPassword() {
let prompt = this.alertCtrl.create({
title: 'Reset Password',
message: "Enter your email address to receive a password reset email",
inputs: [
{
name: 'email',
placeholder: 'Email',
type: 'email'
},
],
buttons: [
{
text: 'Cancel',
handler: data => {
console.log('Cancel clicked', data);
}
},
{
text: 'Send',
handler: data => {
console.log('Send clicked');
}
}
]
});
prompt.present().then(() => {
console.log("presenting")
const firstInput: any = document.querySelector('ion-alert input');
console.log("alert input", JSON.stringify(firstInput))
firstInput.focus();
return;
});
}
使用 .focus() 似乎不起作用。日志JSON.stringify(firstInput)
在 iOS 上显示以下内容:
{
"__zone_symbol__ngModelChangefalse": [{
"type": "eventTask",
"state": "scheduled",
"source": "HTMLInputElement.addEventListener:ngModelChange",
"zone": "angular",
"runCount": 0
}],
"__zone_symbol__inputfalse": [{
"type": "eventTask",
"state": "scheduled",
"source": "HTMLInputElement.addEventListener:input",
"zone": "angular",
"runCount": 0
}],
"__zone_symbol__blurfalse": [{
"type": "eventTask",
"state": "scheduled",
"source": "HTMLInputElement.addEventListener:blur",
"zone": "angular",
"runCount": 0
}],
"__zone_symbol__compositionstartfalse": [{
"type": "eventTask",
"state": "scheduled",
"source": "HTMLInputElement.addEventListener:compositionstart",
"zone": "angular",
"runCount": 0
}],
"__zone_symbol__compositionendfalse": [{
"type": "eventTask",
"state": "scheduled",
"source": "HTMLInputElement.addEventListener:compositionend",
"zone": "angular",
"runCount": 0
}]
}
我能做些什么来解决这个问题?
解决方案
您可以将 cssClass 应用于输入。在您的代码中,
inputs: [
{
name: 'email',
placeholder: 'Email',
type: 'email'
cssClass: 'customClass'
},
]
并将 css 属性应用于 scss 文件中的这个自定义类。
.customClass:focus {
-css properties here-
}
推荐阅读
- html - 位置相对覆盖背景颜色
- csv - 当内容有逗号分隔符时,Sqoop 导出到 teradata 会出错
- apache-poi - apache POI:整个列的dataValidation(或样式),标题行除外?
- amazon-s3 - multer-s3 重命名文件多次上传相同的图像
- sql - 导出包含大文本列的 SQL Server 表
- java - 我可以使用 Eclipse IDE 通过自定义测试用例方法强制 Junit 调试器开始调试执行吗?
- python - 打开文件对象的基类?
- rspec - 如果模拟测试实例内部的方法,如何避免使用 allow_any_instance_of
- sustainsys-saml2 - 如何在现有的网络核心应用程序中使用 Sustainsys.Saml2.AspNetCore2?
- php - Guzzle 的 cookie jar 仅返回来自 example.com 而不是 www.example.com 的 cookie。网站同时发送