Created
August 29, 2016 15:16
-
-
Save premsh/b4b1642f4c09b474485f5c776f8c5abd to your computer and use it in GitHub Desktop.
Angular 1.x directive in TypeScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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