angular - How to extract Data from AngularFire2 Function -
i attempting instantiate variable using angularfire2 function. function authorizeuser()
, when attempt assigning result of function this.user
returned 'undefined' in console window.
import { component, oninit } '@angular/core'; import { angularfire } 'angularfire2'; import { signupservice } '../../../services/signup/signup.service'; @component({ selector: 'console', templateurl: './console.component.html', styleurls: ['./console.component.css'] }) export class consolecomponent implements oninit { signups: any; user : any; constructor( public af: angularfire, private signupservice: signupservice ) {} getsignupslist() { this.signupservice.getsignups().subscribe(signups => { this.signups = signups; }); } authorizeuser() { this.af.auth.subscribe( afdata => { this.user = afdata.auth.email; }); } ngoninit() { this.getsignupslist(); this.authorizeuser(); console.log(this.user); } login() { this.af.auth.login(); } }
however, if console log within promise, proper output seeking :
authorizeuser() { this.af.auth.subscribe( afdata => { this.user = afdata.auth.email; console.log(this.user); }); }
what missing here? want able assign output of afdata.auth.email
global variable: user
the user variable scoped component. it's not global.
Comments
Post a Comment