问题
I am using angular-moment-picker input for datetimepicker, and I want to set today date and current time on the input. Here is my source code. can you please help me. Thank you
<input class="form-control"
format="DD/MM/YYYY HH:mm"
ng-model-options="{ updateOn: 'blur' }"
moment-picker="startDate"
id="startDate"
ng-model="startDate">
回答1:
set default value startDate
when controller initialized
angular
.module('Demo', ['moment-picker'])
.controller('DemoController', ['$scope', function ($scope) {
$scope.startDate = moment();
}]);
回答2:
Use moment() method in script file.
http://embed.plnkr.co/GqJMbeQ5UtSbIutn8elf/
回答3:
You can set start date by using the start-date attribute in your input control. The value should be an moment object.
<input class="form-control"
format="DD/MM/YYYY HH:mm"
ng-model-options="{ updateOn: 'blur' }"
moment-picker="startDate"
id="startDate"
ng-model="startDate"
start-date="startDate">
Here is the working fiddle. Here I have used moment and angular-moment library and module respectively
来源:https://stackoverflow.com/questions/44201003/how-to-set-today-date-and-time-as-default-in-angular-moment-picker