Implementing basic field validation with a FormControl
The simplest form behavior imaginable would be the validation of a single input field. Most of the time, utilizing <form>
tags and going through the rest of the boilerplate is good practice, but for the purpose of checking a single input, it's preferable to distill this down to the bare minimum required in order to use input checking.
Note
The code, links, and a live example related to this recipe are available at http://ngcookbook.herokuapp.com/4076/.
Getting ready
Suppose the following is your initial setup:
[app/article-editor.component.ts] import {Component} from '@angular/core'; @Component({ selector: 'article-editor', template: ` <p>Article title (required):</p> <input required> <button>Save</button> ...
Get Angular 2 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.