javascript - Reject JavaScript promise
问题描述
I am building an Angular application where I have a service for selecting items from a canvas. Once the user clicks a button that allows him to start selecting I also show a snackbar which informs the user that he is in selecting mode and he can start selecting. The snackbar has a cancel button that can stop the selecting mode. The problem is that the selection service returns a Promise that I have to reject if the user cancels the selecting mode from the snackbar. The code:
public startSelecting() {
this.showSnackbar();
// I wait for the user to select something
this.selectionService.getSelection().then(selection => {
// If the user selects an item I can close the snackbar
this.snackbarService.close();
// do something with the selection
});
}
private showSnackbar() {
this.snackbarService.show().subscribe(close => {
// This is an observable that emits if the users cancels the snackbar,
// therefore the selecting mode. Here I want to cancel the Promise from above
});
}
Thanks in advance for any help!
解决方案
推荐阅读
- android - 未解决的参考:匹配器
- c# - 始终从单选按钮中选择第一个枚举
- chatbot - 如何访问动作服务器 5055?(RASA 聊天机器人)
- reactjs - MaterialUI:定义样式组件的简洁方法?
- javascript - Flow:条件函数响应类型
- sql - SQL Join 重复 (M:N)
- jquery - 同时突出显示两个 div 单元格
- php - 如何使用php更改json中特殊键的值?
- scala - 窗口函数 partitionBy 在列表上
- javascript - 如何在 Microsoft Dynamics crm 365 中通过 javascript 获取查找字段的值