Search code examples
angulartypescriptrxjsstoremobx

How to properly get the value of Mobx @observable in TypeScript?


I have a store class which has a property:

@observable customObject: customObject[] = [];

If I wanted to get the value of this observable would I make a method in the same class with:

Option 1

getCustomObject(): Observable<CustomObject[]> {
     return this.customObject;
}
// the observable I'm using would be imported from "rxjs" and not "mobx"

Option 2

getCustomObject() {
     return this.customObject;
}
// How can I subscribe to this observable when the method doesn't return an observable?

Solution

  • According To Ang4 or 6 Use

     getCustomObject(): Observable<CustomObject[]> {
         return this.customObject;
    }
    

    And import observable from rxjs