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) {
ele.html(newValue);compile(ele.contents())(scope);
});
}

}]);