1)html
<p style="min-height:30px;" ng-bind-html="TRA_PlanDetail.Remark| trustHtml"></p>
2)js
angular.module('TyApp').filter('trustHtml', function ($sce) {
return function (input) {
if (input != undefined && input != null && input != '') {
return $sce.trustAsHtml(input.replace(/ /g, ' ').replace(/\n/g, '<br />'));
}
};
});
本文介绍了一种在AngularJS应用中实现HTML安全渲染的方法。通过定义一个名为'trustHtml'的过滤器,该方法可以将普通的HTML字符串转换为安全的AngularJS表达式,从而直接在视图中渲染。此外,此过滤器还实现了将普通文本中的换行符替换为HTML中的<br/>标签,确保了文本格式在网页上的正确显示。
5463

被折叠的 条评论
为什么被折叠?



