<div class="modal-body">
<ul class="nav nav-pills" role="tablist">
<li class="nav-item"><a class="nav-link active" data-toggle="pill" href="#EmployerLogin">Employer</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="pill" href="#seekerLogin">Candidate</a></li>
</ul>
<div class="tab-content">
<div id="EmployerLogin" class="tab-pane active">
<form class="form-horizontal" [formGroup]="registerForm" (ngSubmit)="employerLogin()">
<input type="email" [(ngModel)]="emplogin.employer_email" formControlName="elogin" name="empname" class="form-control"
[ngClass]="{ 'is-invalid': submitted && f.elogin.errors }" placeholder="Email">
<div *ngIf="submitted && f.elogin.errors" class="invalid-feedback">
<div *ngIf="f.elogin.errors.required"> Email is required</div>
</div>
<button class="btn btn-default">Login</button>
</form>
</div>
<div id="seekerLogin" class="tab-pane fade">
<form class="form-horizontal" [formGroup]="registerForm" (ngSubmit)="seekerLogin()">
<input type="text" [(ngModel)]="seekerlogin.seeker_email" formControlName="empEmail" name="empname"
class="form-control" [ngClass]="{ 'is-invalid': submitted && f.empEmail.errors }" placeholder="Email">
<div *ngIf="submitted && f.empEmail.errors" class="invalid-feedback">
<div *ngIf="f.empEmail.errors.required"> Email is required</div>
</div>
<button class="btn btn-default">Login</button>
</form>
</div>
</div>
login.ts
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
@Component({
selector: 'my-Header',
templateUrl: './header.component.html',
})
export class HeaderComponent implements OnInit {
constructor(private formBuilder: FormBuilder) { }
registerForm: FormGroup;
ngOnInit() {
this.registerForm = this.formBuilder.group({
elogin: ['', Validators.required]
});
}
submitted: Boolean = false;
// Employer Login Method
get f() { return this.registerForm.controls; }
employerLogin() {
this.submitted = true;
if (this.registerForm.invalid) {
return;
}
}
// Seeker Login Method
seekerLogin() {
this.submitted = true;
if (this.registerForm.invalid) {
return;
}
}
}
How to validate both forms ,when i am trying to validate one of them its showing error for both side.is there any other way to validate multiple forms in a single component using Angular 6.Please note I am very new to Angular 6 and typescript, so I might be missing something obvious. :)
fin thisf.errorsin your Template?formGroups to do this.