Try as follows:
class SetFocus implements ng.IDirective { //Directive settings restrict :string = 'EA'; scope : any= {}; //Take timeout argument in the constructor constructor(private $timeout: ng.ITimeoutService) { } link: ng.IDirectiveLinkFn = ($scope: ng.IScope, $element: ng.IAugmentedJQuery, $attrs: ng.IAttributes) => { //refer to the timeout this.$timeout(function() { $element[0].focus(); }, 0); } //Expose a static func so that it can be used to register directive. static factory(): ng.IDirectiveFactory { //Create factory function which when invoked with dependencies by //angular will return newed up instance passing the timeout argument var directive: ng.IDirectiveFactory = ($timeout:ng.ITimeoutService) => new SetFocus($timeout); //directive injection list directive.$inject = ["$timeout"]; return directive; } } directives.directive('setFocus', SetFocus.factory());
It may be a problem with the way you have it right now. Since the factory directive is not updated, therefore its constructor will execute with this as a global object. That way, you also won't have a huge constructor, and you can write it properly.
If you have many dependencies introduced instead of repeating the arguments in the factory, you can also:
var directive: ng.IDirectiveFactory = (...args) => new (SetFocus.bind.apply(SetFocus, [null].concat(args)));
source share