Skip to content

Instantly share code, notes, and snippets.

@ugoletti
Last active December 17, 2015 10:08
Show Gist options
  • Save ugoletti/5592108 to your computer and use it in GitHub Desktop.
Save ugoletti/5592108 to your computer and use it in GitHub Desktop.
AngularJS "Compile Html" directive. Compile a HTML partial loaded from external service.
/*
* $scope.test = 'hello world';
* $scope.content = '<div>{{test | uppercase}}</div>';
*
* <div compile-html="content"></div>
*/
angular.module('directives').directive('compileHtml', function ($compile) {
return function(scope, element, attr) {
var unregister = scope.$watch(attr.compileHtml, function (value) {
value = value || '';
if (value) {
element.html($compile(value)(scope));
} else {
element.html(value);
}
});
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment