-1

I Want to return boolean value (only true or false) where my function's return type is Observable < boolean >. How can I return only true or false value in using angular 2. I am trying a lot but unable to solve this problem. How can I do it?

Below is my code :

  CheckValidation(measurementUnitId: string, itemId: string): Observable<boolean> {
    const url = `api/v1.0/measurementUnits/${measurementUnitId}/items/${itemId}`;
    debugger;
    var returnValue = this.http.get(url)
        .do(result => console.log('CheckValidation: ' + result))
        .catch(this.handleError);
    //Here I need the value of returnValue variable will be true or false.
}

Thanks in advance.

R_BD
  • 141
  • 2
  • 8

1 Answers1

0

Although Suren Srapyan beat me to it, I want to clarify this a little more:

If you use the map() operator, you take whatever value you get from the Observable and map it to another value. In your case that could be mapping to true if the server responds with an operation successful or false otherwise.

Outside Subscribers to that Obeservable will not "see" the actual value from the original Observable and only get the boolean value.

For a visual representation see the ReactiveX documentation:

http://reactivex.io/documentation/operators/map.html

Znert
  • 8
  • 2
  • 1