Last active
March 27, 2016 17:25
-
-
Save jamsesso/6e81385c7872b84483f2 to your computer and use it in GitHub Desktop.
ES6 Directives in Angular - Directive registration
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
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