Skip to content

Instantly share code, notes, and snippets.

@Mattnmoore
Last active October 22, 2018 17:08
Show Gist options
  • Select an option

  • Save Mattnmoore/22756ea1ee698a58a828ff82d2d87b70 to your computer and use it in GitHub Desktop.

Select an option

Save Mattnmoore/22756ea1ee698a58a828ff82d2d87b70 to your computer and use it in GitHub Desktop.
Angular Focus Directive
<input focus-input formControlName="address" id="emails-{{ ii }}" class="form-control" type="email" name="emails[]" />
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