Focus on newly added input element

前端 未结 5 1467
臣服心动
臣服心动 2020-11-22 15:28

I have a new Angular 2 app with a list of input boxes. When the user hits the return key, I add a new input box immediately after the one they\'re

5条回答
  •  伪装坚强ぢ
    2020-11-22 15:58

    Take a look at ViewChild, here's a example. This might be what you're looking for:

    import {Component, ViewChild} from 'angular2/core'
    
    @Component({
      selector: 'my-app',
      providers: [],
      template: `
        
    `, directives: [] }) export class App { @ViewChild('name') vc: ElementRef; ngAfterViewInit() { this.vc.nativeElement.focus(); } }

提交回复
热议问题