【发布时间】:2020-01-13 13:03:00
【问题描述】:
我的 Angular 应用程序中有一个与 Contentful 相关的博客提要。感谢 Contentful javascript sdk。
我正在尝试显示标题和文本字段。这是我的代码:
import { Component, OnInit } from '@angular/core';
import {Observable} from 'rxjs';
import {ContentfulService} from '../../services/contentful/contentful.service';
import { Entry } from 'contentful';
@Component({
selector: 'app-blog',
templateUrl: './blog.component.html',
styleUrls: ['./blog.component.scss']
})
export class BlogComponent implements OnInit {
private posts: Entry<any>[] = [];
constructor(private postService: ContentfulService) {}
ngOnInit() {
this.postService.getPosts()
.then(posts => {
this.posts = posts;
console.log(this.posts);
});
}
}
还有html:
<div *ngFor="let post of posts">
<a href="#">{{ post.fields.title }}</a>
<div>{{ post.fields.text }}</div>
</div>
title 字段显示良好,因为它只是一个字符串字段,但text 字段是 RichText 并显示 [object Object]。
实际上它包含几个对象。看起来对象被分成几部分。
https://www.contentful.com/developers/docs/concepts/rich-text/
有人已经在 Angular App 中显示 Contentful RichText 了吗? 有具体的方法吗?
【问题讨论】:
标签: javascript angular typescript contentful