Angular NGXS获取对象的id
我正在编写一个应用程序,通过使用注入了serverService的ngxs,我可以在mongodb中保存事件。当我发送事件时,我不需要id,因为mongo会自动添加id,只需等待它,然后修补状态。(insertEvent returng id然后我查找整个事件并获取它) 当我尝试使用动作处理时,它总是返回带有mock id的事件Angular NGXS获取对象的id,angular,ngxs,Angular,Ngxs,我正在编写一个应用程序,通过使用注入了serverService的ngxs,我可以在mongodb中保存事件。当我发送事件时,我不需要id,因为mongo会自动添加id,只需等待它,然后修补状态。(insertEvent returng id然后我查找整个事件并获取它) 当我尝试使用动作处理时,它总是返回带有mock id的事件 this.actions$.pipe(ofActionSuccessful(CreateEvent)).subscribe((ev) => { consol
this.actions$.pipe(ofActionSuccessful(CreateEvent)).subscribe((ev) => {
console.log(ev)
})
是的,本例中的操作流将返回您调度的操作的有效负载(带有模拟ID) 我可以在这里看到两种选择:
EventCreated
,然后您可以订阅该操作-在此操作负载中,包括刚刚创建的内容的详细信息(ID)。在您的修补程序
操作后分派它withLatestFrom
操作符获取状态的最新视图,并检查`事件数组中的最后一个事件
,以查看生成了什么IDcreateRandom(){
this.store.dispatch(
new CreateEvent(EventFactory.create())
)
}
this.actions$.pipe(ofActionSuccessful(CreateEvent)).subscribe((ev) => {
console.log(ev)
})