我有以下前端代码:
<p>{{ news.content }}</p>
news.content
存储在我的 firebase 数据库中。
如何在不修改前面代码(HTML 或 CSS)的情况下在此文本插值中渲染新行?如果需要,我最终会更改我的前端代码,但我需要快速修复后端,因为我的应用程序处于产品状态,我无法在当天内提供更新......
所以我尝试了\n
, <br />
和
但没有一个起作用...
当我检查 View 时,HTML 如下:
<p>"my text"</p>
所以我猜痛点来自于双引号......
请您知道,我需要这个才能在 iOS 版本上运行。
最佳答案
如果我理解的话,您希望能够渲染一条新线,这要归功于您从组件中获取的对象。
所以我认为你应该使用[innerHTML]
Angular 和 <br>
标签(https://angular.io/guide/template-syntax#!#property-binding-or-interpolation-):
app.component.ts
export class AppComponent{
sometext = 'some text';
anothertext = '<br>new line here';
...
}
app.component.html
<p>{{sometext}} and <span [innerHTML]="anothertext"></span></p>
关于html - 在 Angular 4/Ionic 3 中通过文本插值渲染新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47347094/