我有一个包含换行符 /n 的字符串。试图显示
字符串。它没有将 /n 作为新行,而是将“/n”显示为文本。
$scope.myOutput = " Hello /n"
{{ myOutput | textFormat }}
必需 -> 你好(在 html 页面上)
试过:
app.filter('textFormat', function() {
return function(x) {
return x.replace(/\\n/g, '<br/>');
}
尝试过 css 样式,例如 white-space: pre;
原文由 Rk R Bairi 发布,翻译遵循 CC BY-SA 4.0 许可协议
这不会取代它,但您可以使用 CSS 属性
white-space: pre-line;
在浏览器中呈现 \n: https ://developer.mozilla.org/en-US/docs/Web/CSS/white -空间