【发布时间】:2018-03-05 23:45:14
【问题描述】:
// ticker$ will update every 3s
// showHand$ will only triger after user click button
// I would like to take last ticker price as user order price when user click button
let lastPrice: number;
this.ticker$
// What I am doing now is preserve value to vairable here.
.do(ticker => lastPrice = ticker.closePrice)
.switchMap(() => this.showHand$)
.subscribe(showHand => {
// use value here
this.order.price = lastPrice;
this.order.amount = showHand.amount;
this.order.type = showHand.type;
this.submit();
});
关于如何在没有像上面那样的一个 line 变量的情况下一起保存 value 和 switch map 的任何问题?
【问题讨论】:
-
请考虑将接受的答案更改为 Cameron 发布的结果选择器解决方案。无需使用其他运算符,withLatestFrom 有一些注意事项。
标签: javascript angular typescript rxjs observable