I have two components, they are like this
MessageComponent.ts
@Component({
selector: 'Message',
template: `
<InlineReply *ngIf="show"></InlineReply>
<a *ngIf="!show" (click)="toggleForm()">reply</a>
`
})
export class Message {
public show: boolean = false
toggleForm(){
this.show = this.show ? false : true
}
onSub(status: boolean){
this.toggleForm()
}
}
InlineReplyComponent.ts
@Component({
selector: 'InlineReply',
template: `
<form (ngSubmit)="onSubmit()">
<input name="message" placeholder="Reply..." />
<button type="submit" disabled>Post</button>
</form>
`
})
export class InlinePost{
onSubmit(): void {
this.submitted = true;
}
}
What it does is, when you click the reply link in MessageComponent, a form will show up.
What I want to do is, when the form shows, the input will auto focus. Any idea?
Edit: The answer on similar topic doesn't work for this code