标签:
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" />
标签:
原文地址:http://www.cnblogs.com/rubekid/p/4830670.html