1

I'd like to create an Observable using as source a variables: this.pending.

I want to create an Observable which generates a feed every time this.pending value changes.

I mean, when I do:

this.pending = false;

in some place of my code, I want to receive a false feed on my subscription, and so on...

Any ideas?

Jordi
  • 20,868
  • 39
  • 149
  • 333

1 Answers1

2

Just use BehaviorSubject.

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

and somewhere

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

Then every time you execute

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

subscription gets new value from this.pending.

krystianpe
  • 136
  • 3