import { Component , OnInit } from '@angular/core' ; import { Router , ActivatedRoute } from '@angular/router' ; import 'rxjs/add/operator/first' ; import { AuthenticationService } from '../_services/index' ; @ Component ( { moduleId : module . id , templateUrl : 'login.component.html' } ) export class LoginComponent implements OnInit { model : any = { } ; loading = false ; returnUrl : string ; error = '' ; constructor ( private route , private router , private authenticationService ) { } ngOnInit ( ) { this . authenticationService . logout ( ) ; this . returnUrl = this . route . snapshot . queryParams [ 'returnUrl' ] || '/' ; } login ( ) { this . loading = true ; this . authenticationService . login ( this . model . username , this . model . password ) . first ( ) . subscribe ( data => { this . router . navigate ( [ this . returnUrl ] ) ; } , error => { this . error = error ; this . loading = false ; } ) ; } }