How to return value from function which has Observable subscription inside?

Discussão em 'Angular' iniciado por Teddy, Março 13, 2025.

  1. Teddy

    Teddy Guest

    I dont know how to extract value from Observable to be returned by function in which Observable is present. I need just a value from it to be returned, nothing else.

    Current version which works

    function getValueFromObservable() {
    this.store.subscribe(
    (data:any) => {
    console.log(data)
    }
    )
    }
    getValueFromObservable()


    I need this to work, function to return value, and then:

    function getValueFromObservable() {
    this.store.subscribe(
    (data:any) => {
    return data
    }
    )
    }
    console.log(getValueFromObservable())


    What am I doing wrong here?

    Continue reading...

Compartilhe esta Página