Skip to content Skip to sidebar Skip to footer

How To Get Min And Max Values Of Input Angularjs

currently I'm using a custom directive which wraps the ng-minlength and ng-maxlength directives to apply the values of these directives to the model of the input. I need to do thi

Solution 1:

If you want just to inform the user about the min and the max:

var app = angular.module('myApp',[]);

app.controller('MyCtrl',function($scope){
    $scope.minValue = 5;
    $scope.maxValue = 10;
});
<scriptsrc="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><divng-app="myApp"><divng-controller="MyCtrl"><formname="myForm">
    Last name: <inputtype="text"name="lastName"ng-model="user.last"ng-minlength="{{minValue}}"ng-maxlength="{{maxValue}}"><spanclass="error"ng-show="myForm.lastName.$error.minlength">
      Should be {{minValue}} charachters long</span><spanclass="error"ng-show="myForm.lastName.$error.maxlength">
      No more than {{maxValue}} characters please</span><br></form></div></div>

Post a Comment for "How To Get Min And Max Values Of Input Angularjs"