Created
October 27, 2015 09:21
-
-
Save csvan/48ca3949c9ce25769731 to your computer and use it in GitHub Desktop.
Dynamic instantiation of AngularJS directives.
This file contains 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
.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