AngularJS ng-include $compile dynamic template within directive

Here is a directive created by Paul. It can compile dynamic loaded html template with ng-include.

angular.module('YOURAPP', []).directive('ngBindHtmlUnsafeCompile', ["$compile", function ($compile) {
// work like ngBindHtmlUnsafe, but the content of html will be compiled
return function (scope, ele, attrs) {

scope.$watch(attrs.ngBindHtmlUnsafeCompile, function (newValue, oldValue) {


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.