我的前端从文件系统中检索JSON数据并转换为以下数据
"Lorem Ipsum \r\n Lorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem Ipsum "
到
"Lorem Ipsum <br /> Lorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem Ipsum "
使用javascript的字符串替换方法。
我希望以下列方式在html中以正确的换行符显示此字符串。
"Lorem Ipsum
Lorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem IpsumLorem Ipsum "
以下是视图的代码:
<label>{{ formatJSON(string) }}</label>
formatJSON
是Angular函数,它基本上将\r\n
更改为<br/>
。
我该如何正确地做到这一点?