Skip to content

Instantly share code, notes, and snippets.

@chani24
Created July 15, 2020 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chani24/d9f87683c7d1f7e16c077f1c359c7a42 to your computer and use it in GitHub Desktop.
Save chani24/d9f87683c7d1f7e16c077f1c359c7a42 to your computer and use it in GitHub Desktop.
<div class="nav-wrapper">
<mat-toolbar class="nav">
<span class="logo">Greenpot</span>
<img class="logo-img"src="https://www.pinclipart.com/picdir/big/2-23395_clipart-green-leaf-png-clipart-transparent-png.png">
<span class="example-fill-remaining-space"></span>
<button mat-button routerLink="sign-in" *ngIf="!isAuthenticated">Sign in</button>
<button mat-button routerLink="register" *ngIf="!isAuthenticated">Register</button>
<button mat-icon-button *ngIf="isAuthenticated"><mat-icon>account_circle</mat-icon></button>
<mat-menu #appMenu="matMenu">
<button mat-menu-item>Settings</button>
<button mat-menu-item>Help</button>
<button mat-menu-item (click)='signOut()'>Log out</button>
</mat-menu>
<button *ngIf="isAuthenticated" mat-icon-button [matMenuTriggerFor]="appMenu">
<mat-icon>more_vert</mat-icon>
</button>
</mat-toolbar>
</div>
import { Component, OnInit, OnDestroy } from '@angular/core';
import { AuthService } from '../auth.service';
@Component({
selector: 'app-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.css']
})
export class HeaderComponent implements OnInit, OnDestroy {
constructor(private authservice: AuthService ){
}
isAuthenticated;
ngOnInit(){
this.authservice.getAuthStatus();
this.authservice.currentAuthStatus.subscribe(authStatus => this.isAuthenticated = authStatus)
}
signOut(){
this.authservice.signOut()
}
ngOnDestroy(){
}
}
@urigross
Copy link

I think you might rename getAuthStatus() at ngOnInit() at header.ts to authStatusListener()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment