可能有人知道为什么 NGXS 状态不能在 HttpClient POST 请求中改变。
ctx.patchState()
仅适用于 HTTP POST 请求之外。
@Action(SignIn)
signin(ctx: StateContext<AppStateModel>, { payload }: SignIn) {
// ctx.patchState({isLoggedIn:true}) this works!
return this.api$.signin(payload)
.pipe(
tap((user: User) => {
console.log(user);
ctx.patchState({ isLoggedIn: true })
})
)
.subscribe(
(user: User) => {
ctx.patchState({ isLoggedIn: true })
}
)
}