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. javascript - 新组成的数组打印出来出现问题,里面有对象,但长度为空2. docker网络端口映射,没有方便点的操作方法么?3. angular.js使用$resource服务把数据存入mongodb的问题。4. javascript - [MUI 子webview定位]5. docker绑定了nginx端口 外部访问不到6. dockerfile - 为什么docker容器启动不了?7. 前端 - 怎样让scale缩小的元素不占据原来的空间?8. docker - 各位电脑上有多少个容器啊?容器一多,自己都搞混了,咋办呢?9. macos - mac下docker如何设置代理10. docker-compose 为何找不到配置文件?

网公网安备