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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.