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. angular.js - angular中的a标签不起作用2. 前端 - 类到底该如何去命名 .newsList 这种的命名难道真的不是过度语义化吗?~3. docker api 开发的端口怎么获取?4. docker images显示的镜像过多,狗眼被亮瞎了,怎么办?5. 如何解决Centos下Docker服务启动无响应,且输入docker命令无响应?6. docker不显示端口映射呢?7. golang - 用IDE看docker源码时的小问题8. docker start -a dockername 老是卡住,什么情况?9. javascript - 关于js原生事件的绑定与解除绑定10. docker容器呢SSH为什么连不通呢?

网公网安备