javascript - ng-bind-html中 自定義的指令 不生效!
問題描述
問題:使用ng-bind-html 頁面上已經(jīng)生成了正確的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 - 數(shù)據(jù)庫建字段,默認值空和empty string有什么區(qū)別 1102. 新人求教MySQL關于判斷后拼接條件進行查詢的sql語句3. 在mybatis使用mysql的ON DUPLICATE KEY UPDATE語法實現(xiàn)存在即更新應該使用哪個標簽?4. mysql - 這種分級一對多,且分級不平衡的模型該怎么設計表?5. Navicat for mysql 中以json格式儲存的數(shù)據(jù)存在大量反斜杠,如何去除?6. mysql - 數(shù)據(jù)庫表中,兩個表互為外鍵參考如何解決7. php - 公眾號文章底部的小程序二維碼如何統(tǒng)計?8. mysql - 表名稱前綴到底有啥用?9. mysql - 千萬數(shù)據(jù) 分頁,當偏移量 原來越大時,怎么優(yōu)化速度10. mac OSX10.12.4 (16E195)下Mysql 5.7.18找不到配置文件my.cnf
