Create a directive. For Angular 2+
import { AfterContentInit, Directive, ElementRef, Input } from
> '@angular/core';
> @Directive({
> selector: '[appAutoFocus]'
> })
> export class AutoFocusDirective implements AfterContentInit {
> @Input() public appAutoFocus: boolean;
> public constructor(private el: ElementRef) {
> }
> public ngAfterContentInit() {
> setTimeout(() => {
> this.el.nativeElement.focus();
> }, 500);
> }
> }
Then in your component form, include the tag
<input type="text" appAutoFocus class="form-control">
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.