title: How to subscribe on variable changes?
body: <p>I have declared the following variable:</p>
  
  <pre><code>public filter: IFilterWeekScheduleClassShort = {};
  </code></pre>
  
  <p>How to subscribe on changes(listen object filter)?</p>
  
  <p>I tried this:</p>
  
  <pre><code>private filter: IFilterWeekScheduleClassShort = {};
  private filterChanges: BehaviorSubject&lt;IFilterWeekScheduleClassShort&gt; = new BehaviorSubject(this.filter);
  
  this.filterChanges.subscribe((model) =&gt; {
      console.log(model);
  });
  </code></pre>
  
  <p>Is it okay?</p>
  
  <p>My final code:</p>
  
  <pre><code>public _filter: IFilterWeekScheduleClassShort = {};
  private filterChanges: BehaviorSubject&lt;IFilterWeekScheduleClassShort&gt; = new BehaviorSubject(this._filter);
  
    this.filter = {a: 1, b: 2}
  
    set filter(value: any) {
      this._filter = value;
      this.filterChanges.next(this._filter);
    }
  
    get filter() {
      return this.filterChanges.asObservable();
    }
  </code></pre>
  
  <p>Subscribe on:</p>
  
  <pre><code>this.filter.subscribe(model =&gt; {
     console.log(model);
  });
  </code></pre>
  
  <p>Changes I make from form:</p>
  
  <pre><code>[(ngModel)]="_filter.teacherId"
  </code></pre>