Ninja Ninja - 5 months ago 25
AngularJS Question

can I get an observable value synchronically? (Angular/ReactiveX)

I have an boolean observable in my project that called

isPossible
, this is how it declared:

isPossible: Observable<boolean>;


I want to add condition that this is
isPossible
is
true
, but I want to add it to a place where other conditions are evaluate synchronically, the only way i know how to use the value of observable is with async pipe...like
{{isPossible | async}}
, but here I need to get it synchronically...how can I do it?

Answer

Think of Observable as a kind of Promise which can return more than one value over time. In this case you're creating asynchronous stream which is emitting boolean values. The way you can react to the values is to put your action on subscribe of the stream and then you get the real value:

isPossible.subscribe((latestIsPossibleValue: boolean) => {
  if (latestIsPossibleValue) {
    // do something on 'true'
  }
})

Could you please expand more on the case you've got?

Comments