userForm: FormGroup;
constructor(private formBuilder: FormBuilder) { }
ngOnInit() {
this.setupForm();
}
setupForm() {
this.userForm = this.formBuilder.group({
'username': ['', Validators.required],
'password': ['', Validators.required],
});
}
getErrorMessage(input) {
switch (input) {
case 'user':
if (this.userForm.get('username').hasError('required')) {
return 'Username is required';
}
break;
case 'pass':
if (this.userForm.get('password').hasError('required')) {
return 'Password is required';
}
break;
default:
return '';
}
}
Creating login form in Angular application.
Error TS2564: Property 'userForm' has no initializer and is not definitely assigned in the constructor.
How can this error be resolved?