Set min date to current date in angularJS input -


in angularjs, how can set min attribute of input type="date" current date (today's) ?

<input type="date" ng-model="data.startdate" name="startdate" min=?? /> 

edit1

i did suggested below , added in controller -

$scope.currentdate = new date(); 

and in html -

<input type="date" ng-model="data.startdate" name="startdate" required min="{{currentdate | date:'yyyy-mm-dd'}}" /> <span ng-show="form.startdate.$dirty && form.startdate.$invalid">     <span ng-show="form.startdate.$error.required">start date required</span>     <span ng-show="form.startdate.$error.min">start date should not less current date</span> </span> 

now, year not allowing selected less 2015. also, if whole date less current date, no validation occuring. required validation working fine. .min correct way check field?

thanks

yes can set minimum value. according docs:

<input type="date"        ng-model=""        [name=""]        [min=""]        [max=""]        [required=""]        [ng-required=""]        [ng-change=""]> 

arguments

min (optional) string - sets min validation error key if value entered less min. must valid iso date string (yyyy-mm-dd).

edit set field current date:

controller:

function ctrl($scope) {     $scope.date = new date(); } 

view:

<input type="date" ng-model="data.startdate"          name="startdate" min="{{date | date:'yyyy-mm-dd'}}" /> 

working example here.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -