According to thoughtgram.io, the currently supported validators are:
- required
- minlength
- maxlength
- pattern
So, considering the following code (plunkr here):
@Component({
selector: 'my-app',
template: `
<form #formRef="ngForm">
<input type="number" [(ngModel)]="firstValue" name="firstValue" min="0" required/>
<input type="text" [(ngModel)]="secondValue" maxlength="5" name="secondValue" required/>
<button type="submit"> Submit </button>
</form>
FORM: {{formRef.form | json }}
`
})
export class AppComponent {
firstValue = -22;
secondValue = "eyy macarena!";
}
While minlength
is supported, min="0"
is ignored by angular validation:
So, to make the form result in an error when firstValue ngModel < 0, do I need to build a custom validator?
Question&Answers:os