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. 在windows下安裝docker Toolbox 啟動Docker Quickstart Terminal 失敗!2. golang - 用IDE看docker源碼時的小問題3. 為什么我ping不通我的docker容器呢???4. docker - 各位電腦上有多少個容器啊?容器一多,自己都搞混了,咋辦呢?5. php - TP5的登錄驗證問題6. phpstudy 發現多個后門木馬,有人遇到過嗎?7. node.js - MongoDB安裝啟動8. php如何獲取訪問者路由器的mac地址9. mysql 創建root 用戶出錯,這是什么原因?mysql 中也沒有root用戶10. mysql導入sql大文件語句?
