Component
import { Component, ElementRef, ViewChild, AfterViewInit} from '@angular/core';
...
@ViewChild('input1', {static: false}) inputEl: ElementRef;
ngAfterViewInit() {
setTimeout(() => this.inputEl.nativeElement.focus());
}
HTML
<input type="text" #input1>
More Related Contents:
- Angular error: “Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input'”
- Confirm password validation in Angular 6 [duplicate]
- Set focus on element
- 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
- Limit input field to two decimal places – Angular 5
- How to dynamically add FormControl to FormArray on button click in Angular?
- i got this error when i use command ng new myprojectname to create new project in angular
- Dynamic tabs with user-click chosen components
- Angular HTML binding
- How do I pass data to Angular routed components?
- Angular 2 http.post() is not sending the request
- How can I get new selection in “select” in Angular 2?
- Angular: How to correctly implement APP_INITIALIZER
- Angular 2 – 2 Way Binding with NgModel in NgFor
- Using multiple instances of the same service
- Argument of type ‘string | null’ is not assignable to parameter of type ‘string’. Type ‘null’ is not assignable to type ‘string’
- How to pass query parameters with a routerLink
- Generic email validator
- ng-content select bound variable
- Angular2 @Input to a property with get/set
- Angular 6.0 firebase hosting deploy not working
- Angular2: validation for won’t trigger when changing the file to upload
- Disable Input fields in reactive form
- Tracking scroll position and notifying other components about it
- How do I override the style of primeng components?
- Sanitize input in Angular2 [duplicate]