Answer the question
In order to leave comments, you need to log in
How to add or forward a focus() event to a custom child component in Angular?
An Angular 11 project has a custom button component like this:
@Component({
selector: 'ui-button',
templateUrl: './button.component.html',
styleUrls: ['./button.component.scss']
})
export class ButtonComponent extends ButtonBase {}
<ng-template [ngIf]="alert">
<ui-button #myButton>
</ui-button>
</ng-template>
@ViewChild('myButton') private myCustomButton: ElementRef<HTMLElement>;
this.myCustomButton.nativeElement.focus();
ERROR TypeError: Cannot read property 'focus' of undefined
this.myCustomButton.nativeElement.focus();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question