Trying to construct a reactive Angular form but getting a type error. Here's the angular-html-
<form [formGroup]="newUser" (ngSubmit)='onSubmit()'>
<label>ID</label>
<br>
<input type="text" placeholder="Please Enter Your ID" formControlName="Tz" required>
<span *ngIf="Tz.errors?.minLength && Tz.touched">Your ID must be at least 4 digits long</span>
<span *ngIf="Tz.errors?.maxLength && Tz.touched">Your ID must be at most 9 digits long</span>
<span *ngIf=""></span>
<br>
<label>Email</label>
<br>
<input type="email" placeholder="Please Enter Your Email" formControlName="Email" required>
<span *ngIf="Email.invalid &&Email.touched">Your email does not look right</span>
<br>
<label>Password</label>
<br>
<input type="text" placeholder="Please Choose A Password" formControlName="PW" size="25" required>
<br>
<label>Resubmit Your Password</label>
<br>
<input type="text" placeholder="Please Resubmit Your Password" formControlName="PWVerification" size="30" required>
<br>
<input type="submit" class="btn btn-success" [disabled]="newUser.invalid">
</form>
Here's the typescript:
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl, Validators , FormsModule} from '@angular/forms';
import { RegisterService } from '../register.service';
@Component({
selector: 'app-register',
templateUrl: './register.component.html',
styleUrls: ['./register.component.css']
})
export class RegisterComponent implements OnInit {
public newUser;
public verification;
constructor(public RS: RegisterService) { }
ngOnInit() {
this.newUser = new FormGroup({
Tz: new FormControl ('',[Validators.required,Validators.minLength(4),Validators.maxLength(9)]),
Email: new FormControl ('',[Validators.required,Validators.email]),
PW: new FormControl ('', [Validators.required,Validators.pattern('^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$')]),
PWVerification: new FormControl ('', Validators.required)
})
}
onSubmit() {
console.log(this.newUser.value);
/*this.RS.RegisterUser(this.newUser.value).subscribe(
)*/
}
}
I am sure I am missing something but I simply can't put my finger on it.
Also, it the required attribute on the angular HTML necessary if I have set validators.required to all formcontrolnames on the TS side or is it redundant?
Thanks in advance