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
Asked
Active
Viewed 1,334 times
1 Answers
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();
}
}

Chellappan வ
- 23,645
- 3
- 29
- 60
-
Should probably use AfterContentInit instead, to avoid "expression changed after checked" error. – Jakob Kruse May 11 '23 at 10:08