Skip to content

Instantly share code, notes, and snippets.

@miebach
Forked from BrainCrumbz/directives.js
Created July 29, 2014 18:30
Show Gist options
  • Select an option

  • Save miebach/fc48bf03bceb01bf590d to your computer and use it in GitHub Desktop.

Select an option

Save miebach/fc48bf03bceb01bf590d to your computer and use it in GitHub Desktop.

Revisions

  1. @BrainCrumbz BrainCrumbz created this gist Jun 18, 2013.
    22 changes: 22 additions & 0 deletions directives.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    // 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;
    this.link = 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);
    }