aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/admin/users/user-add/user-add.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/admin/users/user-add/user-add.component.ts')
-rw-r--r--client/src/app/admin/users/user-add/user-add.component.ts18
1 files changed, 11 insertions, 7 deletions
diff --git a/client/src/app/admin/users/user-add/user-add.component.ts b/client/src/app/admin/users/user-add/user-add.component.ts
index 30ca947a0..b7efd3a80 100644
--- a/client/src/app/admin/users/user-add/user-add.component.ts
+++ b/client/src/app/admin/users/user-add/user-add.component.ts
@@ -1,5 +1,6 @@
1import { Control, ControlGroup, Validators } from '@angular/common'; 1import { Validators } from '@angular/common';
2import { Component, OnInit } from '@angular/core'; 2import { Component, OnInit } from '@angular/core';
3import { FormGroup, FormControl, REACTIVE_FORM_DIRECTIVES } from '@angular/forms';
3import { Router } from '@angular/router'; 4import { Router } from '@angular/router';
4 5
5import { UserService } from '../shared'; 6import { UserService } from '../shared';
@@ -7,24 +8,27 @@ import { UserService } from '../shared';
7@Component({ 8@Component({
8 selector: 'my-user-add', 9 selector: 'my-user-add',
9 template: require('./user-add.component.html'), 10 template: require('./user-add.component.html'),
11 directives: [ REACTIVE_FORM_DIRECTIVES ]
10}) 12})
11export class UserAddComponent implements OnInit { 13export class UserAddComponent implements OnInit {
12 userAddForm: ControlGroup; 14 userAddForm: FormGroup;
13 error: string = null; 15 error: string = null;
16 username = '';
17 password = '';
14 18
15 constructor(private router: Router, private userService: UserService) {} 19 constructor(private router: Router, private userService: UserService) {}
16 20
17 ngOnInit() { 21 ngOnInit() {
18 this.userAddForm = new ControlGroup({ 22 this.userAddForm = new FormGroup({
19 username: new Control('', Validators.compose([ Validators.required, Validators.minLength(3), Validators.maxLength(20) ])), 23 username: new FormControl('', [ <any>Validators.required, <any>Validators.minLength(3), <any>Validators.maxLength(20) ]),
20 password: new Control('', Validators.compose([ Validators.required, Validators.minLength(6) ])), 24 password: new FormControl('', [ <any>Validators.required, <any>Validators.minLength(6) ]),
21 }); 25 });
22 } 26 }
23 27
24 addUser(username: string, password: string) { 28 addUser() {
25 this.error = null; 29 this.error = null;
26 30
27 this.userService.addUser(username, password).subscribe( 31 this.userService.addUser(this.username, this.password).subscribe(
28 ok => this.router.navigate([ '/admin/users/list' ]), 32 ok => this.router.navigate([ '/admin/users/list' ]),
29 33
30 err => this.error = err 34 err => this.error = err