MainApp.directive('ngHtml', function () { function watch(scope, el, watchExp){ scope.$watch(watchExp , function(html){ if(el.data("replace")){ el.after(html || ''); el.remove(); } else { el.html(html||""); } }); } return function(scope , el , attr){ var innerText = $.trim(el.text()); if(/^{{.*}}$/.test(innerText)){ var watchExp = innerText.replace(/^{{(.*)}}$/, '$1'); watch(scope, el, watchExp); } else if(attr.value){ watch(scope, el, attr.value); } }; });
<ng-html >{{html}}</ng-html>
<ng-html value="html" data-replace="true" />