Skip to content

Instantly share code, notes, and snippets.

Last active October 25, 2017 18:01
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Example of Angular Directive as ES6 class with injection
class myDirective {
constructor(userService) {
this.template = `<div>{{fullName}}</div>`;
this.restrict = 'E';
this.scope = {
user: '='
}; = 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