title: Angular 9: Observable Getter Returning Object Instead of Boolean from BehaviorSubject
body: <p>My apologies if this is posted somewhere on Stack Overflow, but I'm not finding a answer that works for me.</p>
  <p>I have a BehaviorSubject that tracks a state as a boolean value. I also have a public getter method that is an Observable that returns the BehaviorSubject. I do this so that not only can I subscribe to changes in the BehaviorSubject value, but to also get the current value when it hasn't changed. While I'm able to get the proper value from subscribe, I am getting an Object returned when just calling the getter. I want it to return the last value.</p>
  <p>I've tried using .getValue(), which does not seem to work, and I've tried .value, which does seem to work but throws an error in the IDE.</p>
  <p>I've created a very basic example of what I'm trying to accomplish and I've put comments in the my.service.ts file to show what I'm going for. Please advise. Thank you!</p>
  <p>EDIT: I used what was in stack blitz by default and assigned the getter to the name variable just to see it. My goal is to get the value so that I can do something based on wether the value is true or false. I'm sure I'm missing something really simple.</p>
  <p>EDIT: Adding code to question as requested</p>
  <p>EDIT: I've also added the .subscribe to show that while I understand that's how Observables work, I also want to check the value OUTSIDE of a value change using the same getter if it is possible.</p>
  <p><strong>MyService</strong></p>
  <pre><code>import { Observable, BehaviorSubject } from &quot;rxjs&quot;;
  
  export class MyService {
  
    constructor() {}
  
    private _isBoolean = new BehaviorSubject&lt;boolean&gt;(false);
  
    public get isBoolean(): Observable&lt;boolean&gt; {
      //return this._isBoolean.value; // Returns boolean, but throws error &quot;Type 'boolean' is not assignable to type 'Observable&lt;boolean&gt;'.&quot;
      return this._isBoolean; // Returns object, but I want the value
    }
  
  }
  </code></pre>
  <p><strong>AppComponent</strong></p>
  <pre><code>import { Component } from '@angular/core';
  import { MyService } from './my.service';
  
  @Component({
    selector: 'my-app',
    templateUrl: './app.component.html',
    styleUrls: [ './app.component.css' ]
  })
  export class AppComponent  {
    name;
  
    constructor(private _myservice: MyService) {
      this._myservice.isBoolean.subscribe(val =&gt; {
        console.log(&quot;value from subscribe: &quot; + val)
      })
  
      this.name = this._myservice.isBoolean;
      if (this._myservice.isBoolean) {
        console.log(&quot;true!&quot;);
      } else if (!this._myservice.isBoolean) {
        console.log(&quot;false!&quot;);
      }
    }
  }
  </code></pre>
  <p><a href="https://stackblitz.com/edit/angular-hhdgrc" rel="nofollow noreferrer">https://stackblitz.com/edit/angular-hhdgrc</a></p>