0

So I have 3 observables: updateCustomUserData$, updateEmail$, updatePassword$. And 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. Is anybody can help? P.S. Sorry for my English:)

1 Answers1

0

When onSubmit method is called?
I think you should define ngOnInit instead of onSubmit.

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