Skip to content

Instantly share code, notes, and snippets.

@premsh
Created August 29, 2016 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save premsh/b4b1642f4c09b474485f5c776f8c5abd to your computer and use it in GitHub Desktop.
Save premsh/b4b1642f4c09b474485f5c776f8c5abd to your computer and use it in GitHub Desktop.
Angular 1.x directive in 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());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment