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. mysql 可以從 TCP 連接但是不能從 socket 鏈接2. sql語句 - 如何在mysql中批量添加用戶?3. mysql - 數據庫建字段,默認值空和empty string有什么區別 1104. mysql - JAVA怎么實現一個DAO同時實現查詢兩個實體類的結果集5. mysql建表索引問題求助6. javascript - 按鈕鏈接到另一個網址 怎么通過百度統計計算按鈕的點擊數量7. 怎么php怎么通過數組顯示sql查詢結果呢,查詢結果有多條,如圖。8. 事務 - mysql共享鎖lock in share mode的實際使用場景9. mysql - PHP定時通知、按時發布怎么做?10. mysql 非主鍵做范圍查找實現原理的一點困惑
