国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

javascript - ng-bind-html中 自定義的指令 不生效!

瀏覽:181日期:2024-03-05 16:13:53

問題描述

問題:使用ng-bind-html 頁面上已經生成了正確的html代碼,但是標簽中的 指令 不生效!js代碼:

javascript - ng-bind-html中 自定義的指令 不生效!

html代碼:

javascript - ng-bind-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>

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 庆阳市| 贺州市| 呼和浩特市| 仁寿县| 潮州市| 全南县| 鄯善县| 泸西县| 古浪县| 楚雄市| 铜陵市| 措勤县| 达孜县| 绥芬河市| 黄石市| 白山市| 定襄县| 清原| 上虞市| 巫溪县| 白玉县| 河西区| 宣城市| 个旧市| 富源县| 尼玛县| 张掖市| 岳阳县| 安阳市| 井冈山市| 九江市| 华亭县| 大宁县| 陆良县| 德江县| 台湾省| 蚌埠市| 南溪县| 迭部县| 桓仁| 图片|