There's more...

If you carefully inspect the model data, you will note that the model is still updating with an invalid data even if the ngModel's state is invalid. This would cause quite an issue if a user attempted to submit the form, knowing that there were errors on it. Luckily, Angular's ngForm context is also aware of the state of all ngModel instances within it. We can inspect this state in a similar manner to our ngModel states.

<div class="modal-body">  <form #postForm="ngForm" (ngSubmit)="submit()">    ...  </form></div><div class="modal-footer">  ...  <button type="button" class="btn btn-primary"     (click)="submit()" [disabled]="!postForm.form.valid">Submit  </button></div>

By looking for the valid property of our form, we can help prevent ...

Get MEAN Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.