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. java - android代码重构:如何把app设置里的头像UI做成通用的?2. java - 如何写一个intellij-idea插件,实现编译时修改源代码的目的3. javascript - ios返回不执行js怎么解决?4. javascript - vue-router怎么不能实现跳转呢5. 为什么php修改数据无法同步到数据库,只是当前页面修改成功?6. css3 - 一个关于CSS雪碧图的问题7. javascript - node内存溢出问题8. java - String s=new String()与String s = ""的区别9. node.js - mysql如何通过knex查询今天和七天内的汇总数据10. docker Toolbox在win10 家庭版中打开报错

网公网安备