Forked from royto/ES6 Angular Directive with injection
Created
March 25, 2017 20:41
-
-
Save OlivierPerceboisGarve/6facb2027549c6fbf5704adf2438ced6 to your computer and use it in GitHub Desktop.
Example of Angular Directive as ES6 class with injection
This file contains hidden or 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 { | |
constructor(userService) { | |
this.template = `<div>{{fullName}}</div>`; | |
this.restrict = 'E'; | |
this.scope = { | |
user: '=' | |
}; | |
this.link = function(scope, element) { | |
scope.fullName = userService.getFullName(scope.user); | |
}; | |
} | |
} | |
angular.module('myApp').directive('myDirective', ['userService', | |
(userService) => new myDirective(userService)]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment