RxJs:从字段值变化创建可观察值
问题描述:
我想创建一个Observable
使用作为变量的源:this.pending
。RxJs:从字段值变化创建可观察值
我想要创建一个Observable,它每次产生一个feed时this.pending
值的变化。
我的意思是,当我这样做:
this.pending = false;
在一些地方我的代码,我希望收到我的签约上的false
饲料,等等...
任何想法?
答
只需使用BehaviorSubject
。
this.pending = new BehaviorSubject<boolean>(false)
和地方
subscription = this.pending.subscribe(console.log)
,则每次执行
this.pending.next(true)
或this.pending.next(false)
subscription
从this.pending
获得新的价值。
http://stackoverflow.com/a/35219772/4826457 –
使用反应形式 – Maxime
互联网上的任何例子? – Jordi