2017-04-25 58 views
0

我想創建一個Observable使用作爲變量的源:this.pendingRxJs:從字段值變化創建可觀察值

我想要創建一個Observable,它每次產生一個feed時this.pending值的變化。

我的意思是,當我這樣做:

this.pending = false; 

在一些地方我的代碼,我希望收到我的簽約上的false飼料,等等...

任何想法?

+0

http://stackoverflow.com/a/35219772/4826457 –

+0

使用反應形式 – Maxime

+0

互聯網上的任何例子? – Jordi

回答

1

只需使用BehaviorSubject

this.pending = new BehaviorSubject<boolean>(false) 

和地方

subscription = this.pending.subscribe(console.log) 

,則每次執行

this.pending.next(true)this.pending.next(false)

subscriptionthis.pending獲得新的價值。