1 import { Component } from '@angular/core';
2 import { FormControl } from '@angular/forms';
3 import { Validators } from '@angular/forms';
4 import { Router } from "@angular/router";
5 import { UserService } from "../user.service";
9 templateUrl: './user.component.html',
10 styleUrls: ['./user.component.less']
12 export class UserComponent {
14 usernameForm = new FormControl('', [ Validators.required, this.noWhitespaceValidator ]);
17 var input = this.usernameForm.getRawValue();
19 this.userService.setUser(input.trim());
20 this.router.navigate(['chatrooms'])
24 noWhitespaceValidator(control: FormControl) {
25 const isWhitespace = (control.value || '').trim().length === 0;
26 const isValid = !isWhitespace;
27 return isValid ? null : { 'whitespace': true };
31 private userService: UserService,
32 private router: Router) {}