【发布时间】:2018-10-08 18:59:57
【问题描述】:
Angular 6
Firestore
我有一个存储在 Firestore 中的博客 article 对象。我正在使用所见即所得的编辑器来编辑并将article.content(它是一个字符串)保存到数据库中。 article.content 保存后的样子是这样的:
"<p>Some content.<p><br><p>More content</p>"
它也以这种方式呈现,未设置样式,显示所有 HTML 标记。
如何渲染它,以便内容由标签设置样式并且不显示标签?
这里是代码。
# article-detail-component.ts
export class ArticleDetailComponent {
articlesCollection: AngularFirestoreCollection<Article>;
article: any;
id: any;
constructor (private route: ActivatedRoute,
private afs: AngularFirestore) {
this.articlesCollection = this.afs.collection('articles');
this.route.params.subscribe(params => {
this.id = params['id'];
});
this.articlesCollection.doc(`${this.id}`).ref.get().then((doc) => {
this.article = doc.data();
});
}
}
# article-detail-component.html
<app-ngx-editor [(ngModel)]="article.content"></app-ngx-editor>
<hr>
<div>
{{article.content}}
</div>
【问题讨论】:
标签: html angular string typescript wysiwyg