Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.