Last active
August 29, 2015 14:17
-
-
Save aclave1/fd5e31bf5bd5e2a4370f to your computer and use it in GitHub Desktop.
A provider for a "directive builder". Inject this provider into a directive declaration and return its invocation and it will build a directive definition object. I got this idea from angular-ui-bootstrap's code here: https://github.com/angular-ui/bootstrap/blob/master/src/tooltip/tooltip.js#L12
This file contains hidden or 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
module.exports = function () { | |
this.$get = [function () { | |
return function directiveBuilder(config) { | |
var options = config || {}; | |
return { | |
replace: true, | |
restrict: "E", | |
template: "<div></div>", | |
//template:function(telem,tattrs){return "<div></div>";} | |
//templateUrl:'/url/to/template', | |
//transclude:true,false,element | |
//scope:true,false,{} | |
//controllerAs | |
//require:'othercontroller' | ['multiple','controllers'],'^parent' | |
controller: ["$scope", function ($scope) { | |
}], | |
compile:function(tElem, attrs){ | |
return { | |
post:function postLink(scope, iElement, iAttrs, controller){}, | |
pre:function preLink(scope, iElement, iAttrs, controller){ | |
/** | |
* useful if you want to operate on the scope BEFORE your children compile. | |
* If this directive has child directives inside of it | |
* and it wants to set a property on the scope for them to see, it needs to do that in prelink. | |
* */ | |
} | |
}; | |
} | |
}; | |
}; | |
}]; | |
}; |
This file contains hidden or 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
var directiveBuilder = require('./directivebuilder'); | |
angular.module('gistmodule',[]) | |
.provider('directivebuilder',directiveBuilder) | |
.directive('myDirective',['directivebuilder',function(directivebuilder){ | |
return directivebuilder({option1:'',option2:''}); | |
}]) | |
.directive('myOtherSimilarDirective',['directivebuilder',function(directivebuilder){ | |
return directivebuilder({option1:'',option2:''}); | |
}]) | |
; | |
//template | |
<my-directive></my-directive> | |
<my-other-similar-directive></my-other-similar-directive> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment