Angular Min Max validators example with Angular2

Angular Min Max validators example with Angular2

Angular Min Max validators :: In this post we will show you how to check Min Max validators. we use Angular 2.0.0 for Min Max validators and check value is Min Max validators.

hear we pass two value and check it is between two number, if number is between then we pass positive result else we display error.

Implementation of Min Max validators directives for Angular 2.0.0. it is works with both Angular forms DOM and validation. These two validator directives are absent from initial Angular 2.0.0 @angular/forms/src/validators.ts.

View DemoGit

How to use Angular Min Max validators

On an input field, set we need for minimum min="NUMBER" and/or maximum max="NUMBER" where "NUMBER" work a number. The validators also works with property binding, so for minimum [min]="VARIABLE" and/or maximum [max]="VARIABLE" where "VARIABLE" is "VARIABLE" for a local class variable.

Html code for Min Max validators example with Angular2

<div class="container-fluid">
<div class="col-md-5">
<form class="form-inline row gutter">
<div class="form-group">
<input name="min" type="number" class="form-control" [(ngModel)]="minv" (ngModelChange)="fixMin()">
<div class="form-group">
<input name="max" type="number" class="form-control" [(ngModel)]="maxv" (ngModelChange)="fixMax()">
<form class="row gutter" [ngClass]="{ 'has-error' :  val.errors}" #valForm="ngForm" >
<label>Number between {{minv}} and {{maxv}}</label>
<input class="form-control" name="val" #val="ngModel" type="number" [min]="minv" [max]="maxv" [(ngModel)]="numval" >
<div *ngIf="val.errors" class="row gutter">
<p>{{val.errors | json}}</p>

You also like : Angular Rich Text Editor using Simditor

Leave a Comment

Your email address will not be published. Required fields are marked *

51  +    =  56

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US