import $ from 'jquery' import { Inject, Injectable } from '../decorators' @Injectable('autoFocusService') export default class AutoFocusService { constructor( @Inject('$timeout') private $timeout: ng.ITimeoutService, ) {} // programmatically setting focus does not work if the control has // (a) Not rendered yet // (b) Is currently being animated // (c) Is being re-displayed after previously being hidden // Exposing a manual event that controllers can emit // accepts element id or className so JQuery can find the element // accepts a delay param if there is concern that the element may not be loaded setFocus(elementId: string, delay: number = 0) { this.$timeout( () => $(elementId).focus(), delay) } }