import { Component } from '@angular/core';
-import { FormControl } from '@angular/forms';
-import { Validators } from '@angular/forms';
+import {
+ FormControl,
+ Validators,
+ ValidationErrors,
+} from '@angular/forms';
import { Router } from "@angular/router";
import { UserService } from "./user.service";
usernameForm = new FormControl('', [ Validators.required, this.noWhitespaceValidator ]);
updateName(): void {
- var input = this.usernameForm.getRawValue();
+ let input = this.usernameForm.getRawValue();
if (input !== null) {
this.userService.setUser(input.trim());
this.router.navigate(['chatrooms'])
}
}
- noWhitespaceValidator(control: FormControl) {
+ noWhitespaceValidator(control: FormControl) : ValidationErrors {
const isWhitespace = (control.value || '').trim().length === 0;
const isValid = !isWhitespace;
- return isValid ? null : { 'whitespace': true };
+ return isValid ? {} : { 'whitespace': true };
}
constructor(