I'm currently working with Angular2
and utilizing the two-way binding concept [(ngModel)]
. I have a form on my page that requires validation of the pristine state of an element. To achieve this, I've implemented ngIf
to check the pristine state of the element. However, I'm facing an issue where the condition is not being met consistently. I need to validate the pristine state every time the model changes. Below is a snippet from my app.component.html
:
<form (ngSubmit)="angular2form(myAngular2Form.employeeDob)" [ngFormModel]="myAngular2Form">
<input type="text" class="form-control" id="employee" name="employee" [(ngModel)]="employeeDob" required />
<div *ngIf="employeeDob.pristine">
<p>Please enter the date</p>
</div>
<button type="submit" class="btn btn-primary">Register</button>
</form>
Here is a snippet from my component:
export class AppComponent {
employeeDob: String;
constructor(private myform: FormBuilder) {
this.employeeDob = '';
}
angular2form(date) {
alert("date submitted successfully");
}
}
Any suggestions would be greatly appreciated.