Angular 4 form validation on multiple fields
Your form and validation seems to be working. I updated your plunker and added two divs to your template:
<form [formGroup]="testForm"> <input type="text" formControlName="address"> <input type="text" formControlName="tel"> <input type="text" formControlName="mail"></form><div *ngIf="testForm.valid">Your form is valid! yay!</div><div *ngIf="testForm.invalid">Your form is invalid!</div>
Here's the updated plunk:
I think your validation is correct you just have to show the message for the validation like this
<form [formGroup]="testForm"> <input type="text" formControlName="address"> <input type="text" formControlName="tel"> <input type="text" formControlName="mail"></form><span *ngIf="!testForm.errors.myValidator">Incorrect<span>
and in your validation use this
if(control.get(field1).value=="test" && control.get(field2).value=="test2") { return { myValidator: true } } return { myValidator: false };