-1

First toggle Items to yes, then click on "add row" button. New row will be created, it should always set focus on last created name input field. Here is the stackblitz link set focus on name field

Picture depicts the scenario

1 Answers1

0

You can create custom directive to get input element reference then call focus method on it.

Try this:

import { Directive,ElementRef } from '@angular/core';
import { AfterViewInit } from '@angular/core/src/metadata';

@Directive({
  selector: '[appAutoFocus]'
})
export class AutoFocusDirective implements AfterViewInit {

  constructor(private element:ElementRef) {}

   ngAfterViewInit(){
     this.element.nativeElement.focus();
   }
} 

Forked Working Stackblitz

Chellappan வ
  • 23,645
  • 3
  • 29
  • 60