Edit 2022:
Read a more modern way with @Cichy’s answer below
Modify the show search method like this
showSearch(){
this.show = !this.show;
setTimeout(()=>{ // this will make the execution after the above boolean has changed
this.searchElement.nativeElement.focus();
},0);
}
More Related Contents:
- Read response headers from API response – Angular 5 + TypeScript
- Angular error: “Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input'”
- How to add CORS request in header in Angular 5
- Angular CLI Error: The serve command requires to be run in an Angular project, but a project definition could not be found
- Confirm password validation in Angular 6 [duplicate]
- Compile dynamic HTML in Angular 4/5- something similar to $compile in Angular JS
- How to use Angular4 to set focus by element id
- Angular 5 – Copy to clipboard
- Migrating Angular 4.x to Angular 5 [duplicate]
- Uncaught (in promise): Error: StaticInjectorError(AppModule)[options]
- angular-i18n work-around for translations in code?
- Get access to FormControl from the custom form component in Angular
- Create a reusable FormGroup
- Differences between value and ngValue in Angular 5
- Can’t bind to ‘formControl’ since it isn’t a known property of ‘input’ – Angular2 Material Autocomplete issue
- Angular2 If ngModel is used within a form tag, either the name attribute must be set or the form
- Angular 5 Reactive Forms – Radio Button Group
- How to update / upgrade from Angular 4 to Angular 5+
- Use OpenLayers 4 with Angular 5
- Limit input field to two decimal places – Angular 5
- How to dynamically add FormControl to FormArray on button click in Angular?
- Angular5: Deploying Angular application to multiple clients
- What is the proper use of an EventEmitter?
- No ‘Access-Control-Allow-Origin’ header in Angular 2 app
- Angular4 Exception: Can’t bind to ‘ngClass’ since it isn’t a known property of ‘input’
- To enable or disable the input field based on the value of select component in angular
- Filtering specific column in Angular Material table in angular 5 [duplicate]
- Custom ExceptionHandler change detection lag
- Mocking Child Components – Angular 2
- How to solve the circular dependency