Is it possible set the focus of an input field via a controller once data has loaded (via $resource in this case)?
The input is hidden via ng-show until the data is
Another version of this for Angular.io
import {Directive, ElementRef, Input, OnChanges, SimpleChanges} from '@angular/core';
//Directive to that toggles focus from boolean value set with focusOn
@Directive({
selector: '[focusOn]'
})
export class FocusOnDirective implements OnChanges {
@Input('focusOn') setFocus: boolean;
constructor(private hostElement: ElementRef) {}
ngOnChanges(changes : SimpleChanges) {
(!!changes.setFocus && !!changes.setFocus.currentValue) ?
this.hostElement.nativeElement.focus() :
this.hostElement.nativeElement.blur();
}
}