use login and logout auth service in angular 4

Use auth service for login and logout

–home.component.html

<button class="btn btn-primary" (click)="onLogin()">Login</button>
<button class="btn btn-primary" (click)="onLogout()">Logout</button>

–home.component.ts

import { AuthService } from "../auth.service";

onLogin(){
    this.authService.login();
  }

onLogout(){
    this.authService.logout();
}

Now you can navigate child route of server page when you clicked login button.

Leave a Reply

Your email address will not be published. Required fields are marked *