Skip to content

Instantly share code, notes, and snippets.

@csvan
Created October 27, 2015 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csvan/48ca3949c9ce25769731 to your computer and use it in GitHub Desktop.
Save csvan/48ca3949c9ce25769731 to your computer and use it in GitHub Desktop.
Dynamic instantiation of AngularJS directives.
.directive('dynamicDirective', function ($compile) {
return {
restrict: 'E',
replace: true,
scope: {
directiveName: '@',
directiveParams: '='
},
link: function ($scope, $element, $attr) {
// Dynamically construct the directive
$element.append($compile(`<${directiveName} parameters="directiveParams"> <${directiveName}/>`)($scope));
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment