如果响应为空,如何调用函数
How can I call a function if response is empty
如果响应为空,我如何调用 openSnackbar 函数但 return 如果响应不为空,我如何调用 LoadUserSuccess。我似乎找不到有效的解决方案。
@Effect()
validateOtp$: Observable<Action> = this.actions$.pipe(
ofType<otpActions.Otp>(otpActions.OTP),
switchMap((action) => {
return this.otpService.validateOtp(action.payload).pipe(
map(
(response) => new userActions.LoadUserSucess(response)
// this.openSnackBar()
)
);
})
);
openSnackBar() {
this.snackBar.open('Code invalid / expired', 'Close', {
duration: 3500,
});
}
只需按照以下示例操作即可:
validateOtp$: Observable <Action> = this.actions$.pipe(
ofType<otpActions.Otp>(otpActions.OTP),
switchMap((action) => {
return this.otpService.validateOtp(action.payload).pipe(
tap(x => !x && this.openSnackBar()),
filter(x => !!x),
map(x => new userActions.LoadUserSucess(x))
);
})
);
如果响应为空,我如何调用 openSnackbar 函数但 return 如果响应不为空,我如何调用 LoadUserSuccess。我似乎找不到有效的解决方案。
@Effect()
validateOtp$: Observable<Action> = this.actions$.pipe(
ofType<otpActions.Otp>(otpActions.OTP),
switchMap((action) => {
return this.otpService.validateOtp(action.payload).pipe(
map(
(response) => new userActions.LoadUserSucess(response)
// this.openSnackBar()
)
);
})
);
openSnackBar() {
this.snackBar.open('Code invalid / expired', 'Close', {
duration: 3500,
});
}
只需按照以下示例操作即可:
validateOtp$: Observable <Action> = this.actions$.pipe(
ofType<otpActions.Otp>(otpActions.OTP),
switchMap((action) => {
return this.otpService.validateOtp(action.payload).pipe(
tap(x => !x && this.openSnackBar()),
filter(x => !!x),
map(x => new userActions.LoadUserSucess(x))
);
})
);