javascript - ng-bind-html中 自定義的指令 不生效!
問題描述
問題:使用ng-bind-html 頁面上已經(jīng)生成了正確的html代碼,但是標(biāo)簽中的 指令 不生效!js代碼:

html代碼:

問題解答
回答1:當(dāng)然無法生效,ng-bind-html 等同于 innerHTML。
可以自定義一個(gè)類似 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>
相關(guān)文章:
1. docker鏡像push報(bào)錯(cuò)2. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””3. html5 - datatables 加載不出來數(shù)據(jù)。4. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題5. node.js - mongodb查找子對(duì)象的名稱為某個(gè)值的對(duì)象的方法6. docker 下面創(chuàng)建的IMAGE 他們的 ID 一樣?這個(gè)是怎么回事????7. 運(yùn)行python程序時(shí)出現(xiàn)“應(yīng)用程序發(fā)生異常”的內(nèi)存錯(cuò)誤?8. html5和Flash對(duì)抗是什么情況?9. 測(cè)試自動(dòng)化html元素選擇器元素ID或DataAttribute [關(guān)閉]10. 前端 - @media query 使用出現(xiàn)的問題?

網(wǎng)公網(wǎng)安備