How to set today date and time as default in angular-moment-picker

浪尽此生 提交于 2019-12-08 04:05:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!