简体   繁体   English

Angular iOS 文本字段焦点

[英]Angular iOS text field focus

I need to open mobile keyboard when I open div with input.当我打开带有输入的 div 时,我需要打开移动键盘。 I tried to set the focus for input我试图设置输入的焦点

 this.changeCityInput.nativeElement.focus();

That triggers when I click to parent div.当我单击父 div 时触发。 After click on the parent div child expanding and show an input field单击父 div 子扩展并显示输入字段后

but it doesn't work on ios, for desktop and android it works correctly.但它在 ios 上不起作用,对于桌面和 android 它工作正常。

Also

document.body.ontouchend = () => {
        this.changeCityInput.nativeElement.focus();
      };
setTimeout(() => {
  this.renderer.selectRootElement(this.changeCityInput.nativeElement).focus();

  this.changeCityInput.nativeElement.focus();
}, 500);

Doesnt work.不工作。 What is the correct way to set focus on the input?将重点放在输入上的正确方法是什么?


UPD: On the MacOS works correctly UPD:在 MacOS 上正常工作

focus() doesnt work with disabled button I emulate disabled action焦点()不适用于禁用按钮我模拟禁用操作

For default when i open div with input i focus on it, after finishing i use blur() to unfocus el默认情况下,当我使用输入打开 div 时,我将注意力集中在它上面,完成后我使用 blur() 取消焦点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM