angular - AngularFire2 4.0 Display user email in Header -
im trying display user email in header component following angularfire 2 version 4.0 upgrade documentation: https://github.com/angular/angularfire2/blob/master/docs/version-4-upgrade.md
header.component
import { component, oninit } '@angular/core'; import { authservice } './auth.service'; import * firebase 'firebase/app'; import { observable } 'rxjs/observable'; import { router } '@angular/router'; import { angularfireauth } 'angularfire2/auth'; import { angularfiredatabase, firebaselistobservable,firebaseobjectobservable } 'angularfire2/database'; @component({ selector: 'app-header', templateurl: './header.component.html', styleurls: ['./header.component.css'] }) export class headercomponent implements oninit { user: observable<firebase.user>; constructor(afauth: angularfireauth) { this.user = afauth.authstate; }
header.html
<div> {{ (user | async)? | json }} </div>
if object object in html. if remove question mark outside parenthesis, html displays json lot of info, including email. want display email in html, this:
<div> {{ user?.email }} </div>
my second question have user email in firebase database also. should use firebase auth or firebase database display info? if should use firebase database, how can that?
as always, help!
i stumbled upon problem well. happening user @ moment of evaluation still observable rather result of login. once resolves (|async) email becomes available. in div need put:
{{(user | async)?.email}}
that's it.
hope helps.
Comments
Post a Comment