javascript - ng-bind-html中 自定義的指令 不生效!
問題描述
問題:使用ng-bind-html 頁面上已經生成了正確的html代碼,但是標簽中的 指令 不生效!js代碼:
html代碼:
問題解答
回答1:當然無法生效,ng-bind-html 等同于 innerHTML。
可以自定義一個類似 ng-bind-html-compile 的指令:
.directive(’bindHtmlCompile’, [’$compile’, function ($compile) {return { restrict: ’A’, link: function (scope, element, attrs) {scope.$watch(function () { return scope.$eval(attrs.bindHtmlCompile);}, function (value) { // In case value is a TrustedValueHolderType, sometimes it // needs to be explicitly called into a string in order to // get the HTML string. element.html(value && value.toString()); // If scope is provided use it, otherwise use parent scope var compileScope = scope; if (attrs.bindHtmlScope) {compileScope = scope.$eval(attrs.bindHtmlScope); } $compile(element.contents())(compileScope);}); }}; }]);
<p ng-bind-html-compile='getId(xxx)'></p>
相關文章:
1. javascript - node.js promise沒用2. node.js - nodejs如何發送請求excel文件并下載3. docker-machine添加一個已有的docker主機問題4. docker - 各位電腦上有多少個容器啊?容器一多,自己都搞混了,咋辦呢?5. 為什么我ping不通我的docker容器呢???6. angular.js - 為什么給 Angular 指令綁定事件無法生效7. golang - 用IDE看docker源碼時的小問題8. android 如何實現如圖中的鍵盤上的公式及edittext的內容展示呢9. html5 - 使用angular中,圖片上傳功能中選擇多張圖片是怎么實現的?有什么好的思路嗎?10. java - 我在用Struts2上傳文件時,報以下錯誤怎么回事?
