Angular Autofocus Directive

I’ve had some issues recently with the autofocus attribute not firing consistently in nested Angular views.

Here’s a quick directive that’s resolved it (so far!):

angular
  .module('ec.autofocus', [])
  .directive('autofocus', ['$document', function($document) {
    return {
      link: function($scope, $element, attrs) {
        setTimeout(function() {
          $element[0].focus();
        }, 100);
      }
    };
  }])
;