1 import { Control, ControlGroup, Validators } from '@angular/common';
2 import { Component, OnInit } from '@angular/core';
3 import { Router } from '@angular/router';
5 import { UserService } from '../shared';
8 selector: 'my-user-add',
9 template: require('./user-add.component.html'),
11 export class UserAddComponent implements OnInit {
12 userAddForm: ControlGroup;
15 constructor(private router: Router, private userService: UserService) {}
18 this.userAddForm = new ControlGroup({
19 username: new Control('', Validators.compose([ Validators.required, Validators.minLength(3), Validators.maxLength(20) ])),
20 password: new Control('', Validators.compose([ Validators.required, Validators.minLength(6) ])),
24 addUser(username: string, password: string) {
27 this.userService.addUser(username, password).subscribe(
28 ok => this.router.navigate([ '/admin/users/list' ]),
30 err => this.error = err