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. python - 如何統(tǒng)計(jì)一份英文 API 開發(fā)文檔(如 javadoc文檔)的詞頻?2. mysql優(yōu)化 - mysql 一張表如果不能確保字段列長度一致,是不是就不需要用到char。3. python - oslo_config4. 請教一個(gè)mysql去重取最新記錄5. python - 請問這兩個(gè)地方是為什么呢?6. python - 為什么match匹配出來的結(jié)果是<_sre.SRE_Match object; span=(0, 54), match=’’>7. javascript - 按鈕鏈接到另一個(gè)網(wǎng)址 怎么通過百度統(tǒng)計(jì)計(jì)算按鈕的點(diǎn)擊數(shù)量8. 人工智能 - python 機(jī)器學(xué)習(xí) 醫(yī)療數(shù)據(jù) 怎么學(xué)9. php - 有關(guān)sql語句反向LIKE的處理10. 大家都用什么工具管理mysql數(shù)據(jù)庫?
