Using classes and inherit from ng.IDirective is the way to go with TypeScript:
class MyDirective implements ng.IDirective {
restrict="A";
require="ngModel";
templateUrl="myDirective.html";
replace = true;
constructor(private $location: ng.ILocationService, private toaster: ToasterService) {
}
link = (scope: ng.IScope, element: ng.IAugmentedJQuery, attrs: ng.IAttributes, ctrl: any) => {
console.log(this.$location);
console.log(this.toaster);
}
static factory(): ng.IDirectiveFactory {
const directive = ($location: ng.ILocationService, toaster: ToasterService) => new MyDirective($location, toaster);
directive.$inject = ['$location', 'toaster'];
return directive;
}
}
app.directive('mydirective', MyDirective.factory());
Related answer: https://stackoverflow.com/a/29223360/990356