javascript - How to set the date as a placeholder when view loads? -


i using plugin angular extension when view loads see empty input, when click on input, calendar comes , today's date displayed in input.

what need load today's date in input when view ready.

here way using it

<input type='text' datetimepicker        datetimepicker-options="{format: 'mm/dd/yyyy', usecurrent: true}"/> 

what recommend ?

edit

i added autofocus input, , datepicker it's been displayed, not date need.

my controller:

(function () {   'use strict';    angular     .module('palpatine')     .controller('rotationsctrl', rotationsctrl);    /* @nginject */   function rotationsctrl (rotations, $scope, $rootscope, $state) {     /*jshint validthis: true */     var vm = this;      activate();      function activate () {        $(document).ready(function () {          var today = new date();         var dd = today.getdate();         var mm = today.getmonth()+1; //january 0!         var yyyy = today.getfullyear();          if(dd<10) {             dd='0'+dd         }          if(mm<10) {             mm='0'+mm         }          today = mm+'/'+dd+'/'+yyyy;          $scope.today = moment().format("mm/dd/yyyy");          console.log(today);          $scope.datetimepickeroptions = {           format: 'mm/dd/yyyy',           defaultdate: today         };         });      }   } })(); 

just set defaultdate current date. override usecurrent, it's not needed anymore.

in controller

$scope.datetimepickeroptions = {     format: 'mm/dd/yyyy',      defaultdate: new date() }; 

html

<input type='text'         datetimepicker        datetimepicker-options="{{datetimepickeroptions}}"/> 

edit

it turned out diosney/angular-bootstrap-datetimepicker-directive had bug defaultdate in 0.1.3 release. solution update master branch.

bower.json

"angular-bootstrap-datetimepicker-directive": "#master" 

and run

bower update 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -