我有一个搜索与用户输入搜索匹配的通知的请求,但是每个匹配的通知都有一个 newsId 属性,当我从服务器收到通知时,我希望再次请求从 newsId 属性和之后搜索新闻 obj返回带有通知 obj 和新闻 obj 的 obj
import { Notification } from './notification';
import { New } from './new';
export class NotificationEditResponse {
notification:Notification;
newsBelong?:New;
error?:any;
}
export class EditNotificationsResolverService implements Resolve <NotificationEditResponse> {
constructor(private notificationService:NotificationsService) { }
return this.notificationService.getNotificationById(+id)
.pipe(
flatMap(notificationObj=>{
return this.newsService.getNewById(notificationObj.newsId)
.pipe(
map((res:New)=>({
notification:notificationObj,
newsBelong:res
})),
catchError(error=>{
const msg=`Retrieval error : ${error}`;
console.log(msg);
return of({notification:null, error:msg,newsBelong:null});
})
)
})
);
}
}