Custom Validator on reactive form for password and confirm password matching getting undefined parameters into Angular 4

import {AbstractControl, FormBuilder, FormGroup, Validators} from set your password input into the group and no need to use “ngModel”. <div class=”form-group row” formGroupName=”passwords”> <div class=”form-group”> <label for=”password” class=”control-label”>Contraseña:</label> <input type=”password” class=”form-control” formControlName=”password” title=”Please enter your password”> <p class=”help-block” *ngIf=”signUpForm.get(‘password’).hasError(‘required’) && signUpForm.get(‘password’).touched”>Debe ingresar una contraseña</p> </div> <div class=”form-group”> <label for=”confirmedPassword” class=”control-label”>Confirmar Contraseña:</label> <input type=”password” class=”form-control” formControlName=”confirmedPassword” … Read more

FormBuilder group is deprecated

Problem description From the documentation we see two different lines with the group() function group(controlsConfig: { [key: string]: any; }, options?: AbstractControlOptions): FormGroup AND group(controlsConfig: { [key: string]: any; }, options: { [key: string]: any; }): FormGroup The 2nd definition is what is deprecated The difference in this lines is options?: AbstractControlOptions and options: { … Read more

Angular 4 validator to check 2 controls at the same time

The min, max and required validators can be kept as is. If you want to validate one control based on the value of another, you need to lift the validation to the parent control. import { Component } from ‘@angular/core’; import { ValidatorFn, FormBuilder, FormGroup, Validators } from ‘@angular/forms’; const portStartEnd: ValidatorFn = (fg: FormGroup) … Read more

Angular2 – FormControl Validation on blur

EDIT 2 As Alex and the official documentation says, Angular version 5.0.0 has new option for your ngModel updateOn: ‘blur’ this.email = new FormControl(null, { validators: Validators.required, updateOn: ‘blur’ }); Also you can use other update options: change (default), blur, submit. Original I use directive where remove whole validation on focus and return it back … Read more