简体   繁体   English

有条件的可观察链

[英]Chain of observables with conditions

So I have 3 observables: updateCustomUserData$, updateEmail$, updatePassword$.所以我有 3 个 observables:updateCustomUserData$、updateEmail$、updatePassword$。 And profileEditForm.和profileEditForm。 I need to update profile data if appropriate fields of form was changed;如果更改了适当的表单字段,我需要更新个人资料数据; I think it should look like this:我认为它应该是这样的:

updateCustomUserData$(data) {
  return iif(() => customDataWasChanged(), apiService.updateCustomUserData())
}

// updateEmail$ and updatePassword$ is similar


onSubmit() {
  this.updateCustomUserData$(formData).pipe(
    concatMap(() => this.updateEmail$(newEmail))),
    concatMap(() => this.updatePassword$(newPassword),
  )
  .subscribe(() => doSomething())
}

But it is not working.但它不起作用。 If custom data was not changed and password or email do - updateEmail & updatePassword is not executing.如果自定义数据未更改且密码或 email 执行 - updateEmail 和 updatePassword 未执行。 Is anybody can help?有人可以帮忙吗? PS Sorry for my English:) PS对不起我的英语:)

When onSubmit method is called?何时调用 onSubmit 方法?
I think you should define ngOnInit instead of onSubmit.我认为您应该定义 ngOnInit 而不是 onSubmit。

export class AppComponent implements OnInit {
  ngOnInit() {
    this.updateCustomUserData$(formData).pipe(
      concatMap(() => this.updateEmail$(newEmail))),
      concatMap(() => this.updatePassword$(newPassword),
    )
    .subscribe(() => doSomething())  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM