Skip to content

Instantly share code, notes, and snippets.

@jabyrd3
Last active June 17, 2016 01:34
Show Gist options
  • Select an option

  • Save jabyrd3/412d6b75ec236854705c to your computer and use it in GitHub Desktop.

Select an option

Save jabyrd3/412d6b75ec236854705c to your computer and use it in GitHub Desktop.
stupid directive to add directives to an element for automatically building UI components
(function () {
'use strict';
/* globals _ */
angular.module('application')
.directive('dynamicDirectives', ['$compile', function ($compile) {
return {
restrict: 'A',
scope: true,
transclude: false,
link: function (scope, elem, attr) {
var cloned = elem.clone();
var toAdd = JSON.parse(attr.dynamicDirectives);
_.each(toAdd, function (directive) {
cloned.attr(directive, '');
});
$compile(cloned)(scope);
//elem.replaceWith(cloned);
}
};
}]);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment