javascript - How to return an Observable in angular 4? -


i have method inside authprovider provider class:

getuser() {     return this.afauth.authstate.subscribe(user => {         return user;     }); } 

i subscribe in different class, like:

this.authprovider.getuser().subscribe(user => console.log(user)); 

any ideas how return observable inside getuser() method?

your authstate observable. return authstate , subscribe within function. in function other work can use rxjs#map function.

getuser() : observable {     return this.afauth.authstate.map(...); }  ....  login() {    getuser().subscribe(user => {        return user;    }); } 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -