如果我尝试使用linky过滤代码段,则不再对输入进行清理/渲染/'html-ized'。即我希望能够结合两者的效果:
<div ng-bind-html="snippet"></div>
和
<div ng-bind-html="snippet | linky"></div>
答案 0 :(得分:1)
linky将文本作为输入而不是html。如果你想要一个以html作为输入的过滤器,那么它必须以完全不同的方式工作。请参阅:https://github.com/angular/angular.js/pull/3285#issuecomment-21958391
答案 1 :(得分:0)
抱歉Igor Minar我投票给你答案,但我想看看你的功能没有其他服务:
app.filter('htmlLinky', function($sanitize, linkyFilter) {
var ELEMENT_NODE = 1;
var TEXT_NODE = 3;
var linkifiedDOM = document.createElement('div');
var inputDOM = document.createElement('div');
var linkify = function linkify(startNode) {
var i, ii, currentNode;
for (i = 0, ii = startNode.childNodes.length; i < ii; i++) {
currentNode = startNode.childNodes[i];
switch (currentNode.nodeType) {
case ELEMENT_NODE:
linkify(currentNode);
break;
case TEXT_NODE:
linkifiedDOM.innerHTML = linkyFilter(currentNode.textContent);
i += linkifiedDOM.childNodes.length - 1
while(linkifiedDOM.childNodes.length) {
startNode.insertBefore(linkifiedDOM.childNodes[0], currentNode);
}
startNode.removeChild(currentNode);
}
}
return startNode;
};
return function(input) {
inputDOM.innerHTML = input;
return linkify(inputDOM).innerHTML;
};
});
ng-bind-html =“html | htmlLinky”