Last active
October 22, 2018 17:08
-
-
Save Mattnmoore/22756ea1ee698a58a828ff82d2d87b70 to your computer and use it in GitHub Desktop.
Angular Focus Directive
This file contains hidden or 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
| <input focus-input formControlName="address" id="emails-{{ ii }}" class="form-control" type="email" name="emails[]" /> |
This file contains hidden or 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: '[focus-input]' | |
| }) | |
| export class FocusInput implements AfterViewInit { | |
| constructor(public elem: ElementRef) {} | |
| ngAfterViewInit() { | |
| this.elem.nativeElement.focus(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment