Last active
September 1, 2017 12:57
-
-
Save J2D2Development/16e7b668682d2b0b0c976ff1cdbcf64d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { AfterViewInit, Directive, ElementRef } from '@angular/core'; | |
@Directive({ selector: '[ifautofocus]' }) | |
export class IfAutofocus implements AfterViewInit { | |
constructor(private elementRef: ElementRef) {} | |
ngAfterViewInit() { | |
this.elementRef.nativeElement.focus(); | |
} | |
} | |
/* | |
remember to include it in your module's 'declarations' array, | |
then import it into your component. | |
add it like you would the 'autofocus' tag in your template: | |
<input formControlName="searchTerm" type="text" placeholder="Search!" ifautofocus /> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment