Angular 8 - 在 MergeMap 中赋值 class 属性
Angular 8 - Assign class property inside MergeMap
我正在使用 MergeMap 在我的 Angular 8 应用程序中进行嵌套的 http 调用。但是,我的要求是在 MergeMap 中分配我的模型的 属性,如下面的代码所示。
onFormSubmit(author, email, website, comment) {
let user = new BlogCommenter();
let userComment= new BlogComment();
user.Name = author;
user.Email = email;
user.Website = website;
userComment.Comment = "Some Comment";
userComment.PostId = 1;
userComment.ParentId = 2;
let status = this.userService.postBlogCommenter(user).pipe(
mergeMap(commtr => { userComment.UserId = commtr.Id; this.commentService.postComment() })
);
}
当然,在 mergeMap 中编写的代码无法正常工作,TypeScript 显示的错误是 "Type void isn't assignable to type 'ObservableInput'"。
我的要求是将用户对象的 ID 属性 分配给 BlogComment 对象的 UserId 属性 post 进行第二次 http 调用。
缺少关键字 return
,对于初学者来说,这就是 "void isn't assignable...".
的原因
mergeMap(commtr => {
userComment.UserId = commtr.Id;
return this.commentService.postComment();
});
(是的,订阅让一切发生)。
我正在使用 MergeMap 在我的 Angular 8 应用程序中进行嵌套的 http 调用。但是,我的要求是在 MergeMap 中分配我的模型的 属性,如下面的代码所示。
onFormSubmit(author, email, website, comment) {
let user = new BlogCommenter();
let userComment= new BlogComment();
user.Name = author;
user.Email = email;
user.Website = website;
userComment.Comment = "Some Comment";
userComment.PostId = 1;
userComment.ParentId = 2;
let status = this.userService.postBlogCommenter(user).pipe(
mergeMap(commtr => { userComment.UserId = commtr.Id; this.commentService.postComment() })
);
}
当然,在 mergeMap 中编写的代码无法正常工作,TypeScript 显示的错误是 "Type void isn't assignable to type 'ObservableInput'"。
我的要求是将用户对象的 ID 属性 分配给 BlogComment 对象的 UserId 属性 post 进行第二次 http 调用。
缺少关键字 return
,对于初学者来说,这就是 "void isn't assignable...".
mergeMap(commtr => {
userComment.UserId = commtr.Id;
return this.commentService.postComment();
});
(是的,订阅让一切发生)。