【问题标题】:Trying to render html in ionic试图在离子中呈现html
【发布时间】:2017-03-07 05:38:42
【问题描述】:

我正在尝试渲染一个 html 字符串,以便它使用 Ionic 显示链接等。这是我的第一个 Ionic 应用程序。

<ion-content class="home">
<ion-list>
  <ion-item *ngFor="let f of item">
    <h2 class="question" style="white-space:initial;" ng-bind-html="{{f.question}}">{{f.question}}</h2>
    <p class="answer" style="white-space:initial;" ng-bind-html="{{f.answer}}">{{f.answer}}</p>
  </ion-item>
</ion-list>
</ion-content>

我已经尝试过上面的 ng-bind-html,它说...

未处理的 Promise 拒绝:模板解析错误: 无法绑定到“ng-bind-html”,因为它不是“h2”的已知属性。 ("

我也尝试过 ng-bind-html-safe 但这会产生同样的错误。 如果没有 ng-bind-html 代码,则会显示字符串,但不会解释 html 字符。

另外,这里是来自 .ts 文件的代码

  this.faqService.load()
  .then(data1 => { 
    this.item = data1;
  });

【问题讨论】:

  • ng-bind-html 是 Angular 1。不知道为什么你需要在你的例子中绑定。
  • 那么2中的替换是什么?
  • 检查你刚刚做的链接&lt;p [innerHTML]="{{f.answer}}"&gt; &lt;/p&gt;
  • 哦,试试&lt;p [innerHTML]="f.answer"&gt; &lt;/p&gt;

标签: javascript angularjs ionic2


【解决方案1】:

我的问题的答案是

<p [innerHTML]="f.answer"></p> 

希望这对 Angular 2 / Ionic 的其他新手有所帮助。

【讨论】:

  • 这允许跨站点脚本你应该非常谨慎地使用它。
猜你喜欢
  • 1970-01-01
  • 2016-03-13
  • 2023-03-18
  • 1970-01-01
  • 1970-01-01
  • 2017-06-07
  • 2021-06-03
  • 2010-11-04
  • 2013-01-05
相关资源
最近更新 更多