Focus on field while edit

export class PostsComponent {
    @ViewChild('titleInput') titleInput?: ElementRef;
    ...
    
    onEditPost(post: { id: any; title: string }) {
        this.postTitle = post.title;
        this.editMode = true;
        this.currentPost = post;
        setTimeout(() => {
          if (this.titleInput && this.titleInput.nativeElement) {
            this.titleInput.nativeElement.focus();
          }
        }, 0);
    }

}
Was this page helpful?