Files
component-party/content/2-templating/5-dom-ref/angularRenaissance/inputfocused.component.ts
2025-09-21 23:13:53 +02:00

19 lines
403 B
TypeScript

import {
afterNextRender,
Component,
ElementRef,
viewChild,
} from "@angular/core";
@Component({
selector: "app-input-focused",
template: `<input type="text" #inputRef />`,
})
export class InputFocusedComponent {
inputRef = viewChild.required<ElementRef<HTMLInputElement>>("inputRef");
constructor() {
afterNextRender({ write: () => this.inputRef().nativeElement.focus() });
}
}