Angular 2/4 set focus on input element

后端 未结 4 1124
渐次进展
渐次进展 2021-01-07 20:48

How can I set focus on an input by (click) event? I have this function in place but I\'m clearly missing something (angular newbie here)

sTbState: string = \         


        
4条回答
  •  醉酒成梦
    2021-01-07 21:04

    try this.

    //on .html file
    
    
    // on .ts file
    // navigate to form elements automatically.
    keyDownFunction(event) {
        // specify the range of elements to navigate
        let maxElement = 4;
        if (event.keyCode === 13) {
            // specify first the parent of container of elements
            let container = document.getElementsByClassName("myForm")[0];
            // get the last index from the current element.
            let lastIndex = event.srcElement.tabIndex ;
            for (let i=0; i

提交回复
热议问题