Last active
December 17, 2015 10:08
-
-
Save ugoletti/5592108 to your computer and use it in GitHub Desktop.
AngularJS "Compile Html" directive.
Compile a HTML partial loaded from external service.
This file contains hidden or 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
/* | |
* $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