简体   繁体   English

Angular 2焦点输入模态

[英]Angular 2 Focus in a input of a modal

I'm using modals in a angular project and I need to focus one field inside a modal.This field is part of a @component : 我使用的是模态的角度项目,我需要专注一个领域的modal.This领域内是@Component的一部分:

Autocomplete.html Autocomplete.html

<div #autocomplete>
    <input #input required>
    <ul class="list" *ngIf="isShow()">
        <li>...</li>
        <li>...</li>
    </ul>
</div>

And

Autocomplete.ts 自动完成

@Component({
    selector: 'autocomplete',
    templateUrl: './autocomplete.html'
})
export class Autocomplete 
{
} 

This modal is call from another element of the same @component in the main view and when I clic in the first input, the modal has already been completely rendered so the ngAfterViewInit interface no help me. 这个模态是从主视图中相同@component的另一个元素调用的,当我在第一个输入中选择clic时,模态已经完全渲染,因此ngAfterViewInit interface对我没有帮助。

Any ideas? 有任何想法吗? Thanks 谢谢

Try to add some delay before set the input get focus. 尝试在设置输入焦点之前增加一些延迟。 Please check this answer . 请检查此答案

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

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