对angular来说是新手。我正在使用linky过滤器将href链接添加到一些已被过滤的文本,其中包含换行符。
http://docs-angularjs-org-dev.appspot.com/api/ngSanitize.filter:linky angularjs newline filter with no other html
<section class="description"
ng-bind-html-unsafe="piano.description | noHTML | newlines | linky ">
</section>不过,linky会自动清理html,删除我精心添加的换行符。似乎没有一种被接受的方法来做这件事,什么才是好的呢?创建过滤器来取消转义换行符?自定义linky以添加无过滤器选项?
发布于 2013-12-05 21:27:38
我今天也遇到了同样的问题--最终解决了这个问题,用这里的parseUrlFilter替换了Angular的内部linky-filter:https://stackoverflow.com/a/14693341/2199358
发布于 2014-06-19 01:18:37
您在标题中回答了您自己的问题。使用angular的linky而不使用杀菌器。我只是进入了angular的源代码,复制-粘贴了angular的linky函数而没有进行清理,并将其重命名。
完整代码如下:
发布于 2016-06-08 07:21:05
在类似的情况下,我最终创建了以下指令。它做两件事:
在当前作用域中未编译任何
用法:
<tr ng-repeat="row in newItemHTMLs" replace-with-html="row"></tr>来源:
myApp.directive('replaceWithHtml', ['$parse', '$compile', function($parse, $compile) {
return {
restrict: 'A',
compile: function(tElement, tAttrs) {
var ngBindHtmlGetter, ngBindHtmlWatch;
ngBindHtmlGetter = $parse(tAttrs.replaceWithHtml);
ngBindHtmlWatch = $parse(tAttrs.replaceWithHtml, function(value) {
return (value || '').toString();
});
$compile.$$addBindingClass(tElement);
return function(scope, element, attr) {
$compile.$$addBindingInfo(element, attr.replaceWithHtml);
return scope.$watch(ngBindHtmlWatch, function() {
return element.replaceWith($compile(ngBindHtmlGetter(scope))(scope) || '');
});
};
}
};
}
]);https://stackoverflow.com/questions/17373727
复制相似问题