import { Component } from '@angular/core' ; import { Router } from '@angular/router' ; import { AuthService } from '../../services/auth.service' ; import { User } from '../../models/user' ; @ Component ( { selector : 'login' , templateUrl : './login.component.html' , styleUrls : [ './login.component.css' ] } ) export class LoginComponent { user : User = new User ( ) ; constructor ( private router , private auth ) { } onLogin ( ) { this . auth . login ( this . user ) . then ( ( user ) => { localStorage . setItem ( 'token' , user . json ( ) . auth_token ) ; this . router . navigateByUrl ( '/status' ) ; } ) . catch ( ( err ) => { console . log ( err ) ; } ) ; } }