Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// Define core directive code + attributes and store that as a module value
angular.module('com.namespace.directives').value('MyDirectiveCore', MyDirectiveCore);
function MyDirectiveCore($compile) {
this.restrict = 'A';
this.priority = 10; = postLink;
return this;
function postLink(scope, element, attrs) {
// Use $compile, scope, element, ... whatever
// Define directive to be used in HTML, injecting core definition from previous module
angular.module('com.namespace.directives').directive('myDirective', ['$compile', 'MyDirectiveCore', factory]);
function factory($compile, MyDirectiveCore) {
return new MyDirectiveCore($compile);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment