gpt4 book ai didi

带有 trustAsHtml 的 AngularJS 过滤器

转载 作者:行者123 更新时间:2023-12-01 13:47:38 24 4
gpt4 key购买 nike

我正在尝试制作一个自定义过滤器,用 <br/> 替换新行,像这样:

angular.module('appFilters', []).filter('break_lines', ['$sce', function($sce) {
return function(input) {
return $sce.trustAsHtml(input.replace(/\n/g, "<br />"));
};
}]);

并在这样的模板中使用它:

<div class="home-tag">{{locales.home_tagline | break_lines}}</div>

问题是生成的文本是 html 转义的。

最佳答案

尝试

<div class="home-tag" ng-bind-html="(locales.home_tagline | break_lines)"></div>

希望对你有帮助

关于带有 trustAsHtml 的 AngularJS 过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34672935/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com