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. vim - docker中新的ubuntu12.04鏡像,運行vi提示,找不到命名.2. IOS app應用軟件的id號怎么查詢?比如百度貼吧的app-id=4779278133. python - oslo_config4. android - 京東移動端網頁和其app加載的url所做的呈現不應該是完全一樣的嗎?5. javascript - 關于addEventListener和attachEvent的兼容寫法疑問,求助!6. 非root安裝MySQL5.6報錯,求助?。。?/a>7. vue打包和PHP后臺怎樣同域名部署配置8. 遍歷目錄下的所有文件9. javascript - 釘釘的excel, word文件預覽是直接用的微軟的office web app,不犯法嗎?10. php傳對應的id值為什么傳不了啊有木有大神會的看我下方截圖
