need regarding angular 6 reactive form validation, I have studied from official angular website
I want to validate my form and display the different error message to different error
Component code
this.pinForm = new FormGroup({
'defaultPin': new FormControl(this.pin.oldPin, [
Validators.required,
Validators.minLength(4)
])
});
Html code
<form [formGroup]="pinForm" #formDir="ngForm">
<div class="form-group">
<label for="defaultPin">Default Pin</label>
{{formDir.valid}}
<input type="text" name="defaultPin" class="form-control" id ="defaultPin" aria-describedby="defaultPin" placeholder="Please enter your old Pin"
formControlName = "defaultPin" />
<small id="defaultPin" class="form-text text-muted">Check your Email address for default pin.</small>
{{defaultPin}}
<div *ngIf="defaultPin.invalid && (defaultPin.dirty || defaultPin.touched)"
class="alert alert-danger">
enter code here
<div *ngIf="defaultPin.errors.required">
Name is required.
</div>
<div *ngIf="defaultPin.errors.minlength">
Name must be at least 4 characters long.
</div>
</div>
</div>
But when I run I'm getting this error
ERROR TypeError: Cannot read property 'invalid' of undefined
at Object.eval [as updateDirectives] (AddPinComponent.html:21)
at Object.debugUpdateDirectives [as updateDirectives] (core.js:10756)
at checkAndUpdateView (core.js:10153)
at callViewAction (core.js:10394)
at execComponentViewsAction (core.js:10336)
at checkAndUpdateView (core.js:10159)
at callViewAction (core.js:10394)
at execEmbeddedViewsAction (core.js:10357)
at checkAndUpdateView (core.js:10154)
at callViewAction (core.js:10394)
Please help me
this.pinforminOnInit()?