1 import { Component, OnInit } from '@angular/core';
2 import { Validators } from '@angular/common';
3 import { FormControl, FormGroup, REACTIVE_FORM_DIRECTIVES } from '@angular/forms';
4 import { Router } from '@angular/router';
6 import { AuthService } from '../shared';
10 template: require('./login.component.html'),
11 directives: [ REACTIVE_FORM_DIRECTIVES ]
14 export class LoginComponent implements OnInit {
21 private authService: AuthService,
22 private router: Router
26 this.loginForm = new FormGroup({
27 username: new FormControl('', [ <any>Validators.required ]),
28 password: new FormControl('', [ <any>Validators.required ]),
33 this.authService.login(this.username, this.password).subscribe(
37 this.router.navigate(['/videos/list']);
40 console.error(error.json);
42 if (error.json.error === 'invalid_grant') {
43 this.error = 'Credentials are invalid.';
45 this.error = `${error.json.error}: ${error.json.error_description}`;