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 - thinkphp5 在MAC電腦本地正常,部署LINUX服務器之后,模型不存在2. 這是什么情況???3. javascript - 百度圖片切換圖片時url會改變,但無刷新,沒用hash,IE8也支持,請問是用了什么技術?4. phpadmin的數據庫,可以設置自動變化時間的變量嗎?就是不需要接收時間數據,自動變化5. 老哥們求助啊6. PHP類封裝的插入數據,總是插入不成功,返回false;7. python執行cmd命令,怎么讓他執行類似Ctrl+C效果將其結束命令?8. 編輯管理員信息時,為什么沒有修改過的內容會為空?9. APP上傳到電腦服務器,出現數據上傳不完整的問題10. 求救一下,用新版的phpstudy,數據庫過段時間會消失是什么情況?
