【发布时间】:2019-05-18 07:50:38
【问题描述】:
使用 Angular 7 和反应式表单我在组件上有以下内容:
ngOnInit() {
this.postForm = this.formBuilder.group({
categoryId: [''],
title: [''],
content: ['']
});
}
getPost(postId: number) : Observable<Post> {
return this.postService.getByPostId(postId);
}
其中PostService的GetByPostId方法如下:
public getByPostId(postId: number): Observable<Post> {
return this.httpClient.get<Post>(`posts/${postId}`);
}
postService返回一个Post,接口是:
interface Post {
id: number;
categoryId: number;
title: string;
content: string;
}
从 getPost 返回的内容中填充表单数据的正确方法是什么?
【问题讨论】:
标签: angular angular7 angular-reactive-forms