0

I have this Angular 2 form:

<input #myInput="ngModel" [(ngModel)]="myobj.myInput" required min="0" type="number" /> <p>valid: {{myInput.valid}}</p> 

When I enter "10" it is valid and when I enter "" it's invalid, but when I put "-10" it is still valid.

3
  • It's still valid because it's not a number Commented Nov 30, 2016 at 22:32
  • Not enough information to determine what's going on. Where's the validation code? Commented Nov 30, 2016 at 22:32
  • when is not a number how to make it to be number? Commented Nov 30, 2016 at 22:34

1 Answer 1

0

Because min isn't an option for FormsModule validation. The available validators are required, minlength, maxlength and pattern; an empty input is invalid because you have required. The min attribute prevents the HTML input from decrementing below zero using the arrow keys or the up-down buttons in the input, but isn't used for validation; you could write a custom validator to do this.

Note that there is an issue on GitHub discussing support for the HTML 5 validators; the fact that it's currently closed doesn't bode well for min and max getting included in the near future.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.