Search code examples
angulartypescriptsubscribeangular2-observables

How to get value from Observable


Please have you any idea how to get _value from:

this

I have this function:

jobsLength(){
   const jobslength:any;
   jobslength=this.searchLogic.items$
   console.log(jobslength)
};

Solution

  • You need to subscribe to the items$ Observable to get the data.

    jobsLength() {
       this.searchLogic.items$.subscribe((value: any[]) => {
           let jobs: any[] = value;
           console.log(jobs);
           console.log(jobs.length);
       });
    }
    

    Sample Solution on StackBlitz


    References

    Observable (Subscribing)