【发布时间】: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中的替换是什么?
-
检查你刚刚做的链接
<p [innerHTML]="{{f.answer}}"> </p> -
哦,试试
<p [innerHTML]="f.answer"> </p>
标签: javascript angularjs ionic2