html - 在 Angular 4/Ionic 3 中通过文本插值渲染新行

标签 html angular ionic-framework ionic2 string-interpolation

我有以下前端代码:

<p>{{ news.content }}</p>

news.content存储在我的 firebase 数据库中。

如何在不修改前面代码(HTML 或 CSS)的情况下在此文本插值中渲染新行?如果需要,我最终会更改我的前端代码,但我需要快速修复后端,因为我的应用程序处于产品状态,我无法在当天内提供更新......

所以我尝试了\n , <br />&#13;&#10;但没有一个起作用...

当我检查 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/

相关文章:

html - 无法使用CSS动画垂直翻转导航栏菜单文本

javascript - 单击插入另一个模板

javascript - AngularJS 输入字段未从 Controller 内的 setTimeout 更新

jquery - 在主 div 中滚动 div 的集合

javascript - 在 MobileFirst 8 的 JS HTTP 适配器中添加方法

javascript - Node API 通过 Express 对客户端(Angular2)的正文响应格式错误

javascript - 如何动态添加选项卡到 Angular primeNg tabview 控件?

angular-cli Firebase 托管 Angular 2 路由器不工作

html - Ionic 2 占位符文本样式

android - IONIC 5 Cordova 插件可以构建,但在运行 android 时无法工作。它仅在 -livereload 中工作