import { Component, OnInit} from '@angular/core'; import { AuthService} from '../auth/auth.service'; import { Observable } from 'rxjs'; import { map, share } from 'rxjs/operators'; @Component({ selector: 'app-home', templateUrl: './home.component.html', styleUrls: ['./home.component.css'] }) export class HomeComponent implements OnInit { public user: Observable; constructor(public auth: AuthService) { } ngOnInit() { this.user = this.auth.userObservable.pipe( map (x => x.isAuthenticated ? x.name : null), share() ); } }