Skip to content

Instantly share code, notes, and snippets.

@jamsesso
Last active March 27, 2016 17:25
Show Gist options
  • Save jamsesso/6e81385c7872b84483f2 to your computer and use it in GitHub Desktop.
Save jamsesso/6e81385c7872b84483f2 to your computer and use it in GitHub Desktop.
ES6 Directives in Angular - Directive registration
import { Inject } from 'decorators';
import * as directives from './module';
function factoryize(directive) {
return directive.$inject
? Inject(...directive.$inject)((...dependencies) => new directive(...dependencies))
: () => new directive();
}
const directivesModule = angular.module('app.directives', []);
Object.keys(directives).forEach(key => {
if(!directives[key].__directive) {
console.warn(`Directive ${key} is missing the @Directive decorator.`);
return;
}
const { name } = directives[key].__directive;
directivesModule.directive(name, factoryize(directives[key]));
});
export default directivesModule.name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment