angular - RXJS Stream 在每个复选框/单选更改时触发,但预期行为仅在表单提交时触发
问题描述
我的 UI 上有两个选项卡。
第一个选项卡(默认) - 有一个输入文本框,当用户提交它时,会向服务器发送一个 http 调用(按预期工作)
第二个选项卡 - 相同的输入文本框 + 复选框和单选按钮列表,其中至少必须选择一个。然后在提交表单时,发送 http 调用。
现在,问题是 - 当用户提交第二个选项卡的表单时,我正在汇总选定的复选框和单选值。我已经为 selectedCheckbox 和 selectedRadioButton 提供了一个单独的流,它们按预期工作。用户首次提交表单后会出现此问题。在每次复选框/收音机更改时,都会将 http 调用发送到服务器。我希望它仅在提交表单时才这样做(这也在发生)。所以现在 - http 调用正在表单提交(需要)以及单选/复选框更改(不需要)上发送
下面是代码片段。
我不确定我错过了什么。任何建议都受到高度赞赏。
detailsByAccount$: Observable<MyType> = this.selectedTab$.pipe(
switchMap((tab) => {
//enteredAccount$ = account submitted through form
return this.enteredAccount$.pipe(
switchMap((account) => {
// Server Http call to get the response
if (tab === 'X') {
return this.myService.getDetails(account); // This section works fine
}
// After the form is submitted once, this stream is triggered every time,
//checkbox is checked or radio button is clicked, probably because both the values are available
return combineLatest(this.selectedCheckbox$, this.selectedRadio$).pipe(
concatMap(([selectedCheckbox, selectedRadio]) => this.myservice.getDetails(account, selectedCheckbox, selectedRadio)
)
);
})
);
})
)
解决方案
推荐阅读
- java - 执行正确的代码后,如何阻止我的代码执行每个 println?
- r - 如何根据元素ggplot r的值给出直方图中特定颜色的条形图
- java - 在springboot中获取存储库对象null
- c# - User checked item in CheckedListBox
- javascript - 将 javascript 变量插入到转义的 JSON 字符串中
- java - 每次出现的匹配条件
- c++ - 如何将半个堆栈弹出到另一个堆栈
- reactive-programming - 如何做反应式六边形架构
- python-3.x - Python,Beautifulsoup - 根据列表中的项目从标签中提取字符串
- python - 如何将我的 python 代码集成到我的 tkinter 接口?