0

I'm playing around with observables to help me grasp them a little better.

I know an Observbable is capable of setting data, but I'm wondering if it's possible to return the result instead?

    getDays(): Observable<any> {
        this.quoteService.listDays().subscribe((days) => {
            return days;
        });
    }

Therefore something else would subscribe to getDays.

is this possible?

Musaffar Patel
  • 905
  • 11
  • 26
  • 2
    The observable/subscription pattern is asynchronous. So you cannot return the data synchronous. You need to use some form of async pattern (either a Promise or the observable) to return the data. More info about async data [here](https://stackoverflow.com/q/14220321/6513921). – ruth Jul 27 '20 at 12:13
  • Thanks, it turns out I can just use ````return this.quoteService.listDays();``` no real practical use for this but will help me along the learning curve – Musaffar Patel Jul 27 '20 at 12:28
  • 2
    It'll actually be immensely helpful when you combine the observable with various RxJS [operators](https://rxjs-dev.firebaseapp.com/guide/operators) that helps you refine and control the emissions from the observable. – ruth Jul 27 '20 at 12:38

0 Answers0