【发布时间】:2012-12-07 12:49:16
【问题描述】:
我正在尝试将换行符 (\n) 转换为 html br's。
根据this discussion in the Google Group,这就是我所拥有的:
myApp.filter('newlines', function () {
return function(text) {
return text.replace(/\n/g, '<br/>');
}
});
那里的讨论还建议在视图中使用以下内容:
{{ dataFromModel | newline | html }}
这似乎使用了旧的html 过滤器,而现在我们应该使用ng-bind-html 属性。
无论如何,这会带来一个问题:我不希望将原始字符串 (dataFromModel) 中的任何 HTML 呈现为 HTML;只有br 的。
例如,给定以下字符串:
当 7 > 5
我仍然不想要 html 和这里的东西......
我希望它输出:
While 7 > 5<br>I still don't want html & stuff in here...
有没有办法做到这一点?
【问题讨论】:
标签: javascript html angularjs sanitization