Topic: New Form validation doesn't work correctly
bfk.portal
pro
asked 6 years ago
Hi,
I tried the new way of validation which you suggested on your website but there are a few problems. First of all the docs are pretty strange there is a lot of copy and paste e.g. you always reference input in the *ngIf although the formcontrolname is another.Secondly when i inspect your side you still use your old system which is a big questionmark.
But the real problems started when i tried it with a simple login form.
In my template I wrote(Edit: sorry I don't know what went wrong with the align of the template please just copy it into another editor):
In my Component i built the form:
this.loginForm = this
.fb
.group({
'email':[
'',
[Validators.required,Validators.email]
],
'password':[
'',
[Validators.required]
]
});
and my onSubmit looked like this:
onSubmit() {
if(this.loginForm.valid){
this.loginService.isProcessing=true;
this._loginSubscribtion=this
.loginService
.login(this.loginForm.get('email').value,this.loginForm.get('password').value)
.subscribe(result=>{
console.log('Hello');
console.log(this.router);
if(result===true){
console.log(this.router);
this
.router
.navigate(['home']);
}
});
}
}
But I got the error that email in email.invalid is null so my question what have I done wrong? I hope you can help me.
Best Regards
Matthias
Arkadiusz Idzikowski
staff
answered 6 years ago
Hello,
You need to add getters in your ts file. For example:
get email() { return this.loginForm.get('email'); }
get password() { return this.loginForm.get('password'); }
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Resolved
- ForumUser: Pro
- Premium support: No
- Technology: MDB Angular
- MDB Version: 7.0.0
- Device: Desktop
- Browser: Chrome
- OS: Windows 10
- Provided sample code: Yes
- Provided link: No