From 0f6da32b148c0f4146b2ae9ad1add9a9f00cc339 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 23 Aug 2016 14:37:49 +0200 Subject: Client: update to new form api --- client/src/app/login/login.component.html | 17 ++++++++--------- client/src/app/login/login.component.ts | 23 ++++++++++++++++++----- 2 files changed, 26 insertions(+), 14 deletions(-) (limited to 'client/src/app/login') diff --git a/client/src/app/login/login.component.html b/client/src/app/login/login.component.html index 5848fcba3..636872942 100644 --- a/client/src/app/login/login.component.html +++ b/client/src/app/login/login.component.html @@ -1,16 +1,15 @@

Login

-
{{ error }}
-
+
-
+
Username is required
@@ -18,13 +17,13 @@
-
+
Password is required
- + diff --git a/client/src/app/login/login.component.ts b/client/src/app/login/login.component.ts index ddd62462e..fe867b7b4 100644 --- a/client/src/app/login/login.component.ts +++ b/client/src/app/login/login.component.ts @@ -1,23 +1,36 @@ -import { Component } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; +import { Validators } from '@angular/common'; +import { FormControl, FormGroup, REACTIVE_FORM_DIRECTIVES } from '@angular/forms'; import { Router } from '@angular/router'; import { AuthService } from '../shared'; @Component({ selector: 'my-login', - template: require('./login.component.html') + template: require('./login.component.html'), + directives: [ REACTIVE_FORM_DIRECTIVES ] }) -export class LoginComponent { +export class LoginComponent implements OnInit { error: string = null; + username = ''; + password: ''; + loginForm: FormGroup; constructor( private authService: AuthService, private router: Router ) {} - login(username: string, password: string) { - this.authService.login(username, password).subscribe( + ngOnInit() { + this.loginForm = new FormGroup({ + username: new FormControl('', [ Validators.required ]), + password: new FormControl('', [ Validators.required ]), + }); + } + + login() { + this.authService.login(this.username, this.password).subscribe( result => { this.error = null; -- cgit v1.2.3