angularjs - Angular UI Datepicker json set date not working -
i have angular-ui datepicker, when load date remotely json, datepicker doesn't select date, when type it select date. doesn't show in input blank input, , when click open datepicker correct date selected.
i have date loaded in remotely , shown in datepicker , input field of datepicker.
this code datepicker:
<input type="text" class="form-control" uib-datepicker-popup ng-model="dt" ng-click="open()" ng-change="testfun(dt)" is-open="popup.opened" datepicker-options="dateoptions" ng-required="true" close-text="close" /> <span class="input-group-btn"> <button type="button" class="btn btn-default" ng-click="open()"><i class="glyphicon glyphicon-calendar"></i></button> </span>
code set date:
$scope.today = function() { $scope.dt = moment($scope.tenderdate, "yyyy-mm-dd").format(); }; $scope.today();
$scope.tenderdate following:
$scope.tenderdate = $scope.data.items.date;
which in json
{ "date":"2017-08-02" }
the $scope.tenderdate works , outputs date correctly. why find weird when type in selects date in date picker not in inputfield.
$scope.today = function() { $scope.dt = moment("2017-08-02", "yyyy-mm-dd").format(); }; $scope.today();
and without use of momentjs , write works. , shows correct date "2017-08-02" that.
$scope.today = function() { $scope.dt = new date(2017, 7, 2); };
maybe know way date json in datepicker.
as mentioned in docs need assign $scope.dt
value if normal javascript date format.
in order achieve need use .todate() instead of .format().
your code like:
$scope.today = function() { $scope.dt = moment("2017-08-02", "yyyy-mm-dd").todate(); }; $scope.today();
Comments
Post a Comment