I am trying to use ui-bootstrap components to make datepicker inside modal. Datepicker should send back a date formatted as a unix timestamp.
here are the controllers:
.controller('MyCtrl', [ '$scope', '$modal', function ($scope, $modal) { $scope.open = function () { var modalInstance = $modal.open({ templateUrl: 'tplModal.html', controller: 'MyModalCtrl' }); }; }]) .controller('MyModalCtrl', [ '$scope', '$modalInstance', function ($scope, $modalInstance) { $scope.required= {}; $scope.disabled = function(date, mode) { return ( mode === 'day' && ( date.getDay() === 0 || date.getDay() === 6 ) ); }; $scope.minDate = new Date(); $scope.$watch('dt', function() { if ($scope.dt) $scope.required.timestamp = Math.floor($scope.dt.getTime() / 1000); console.log('timestamp: ', $scope.required.timestamp, '/ dt: ', $scope.dt); }); $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; }]);
and html modality template:
<div class="modal-body"> <div ng-model="dt"> <datepicker min="minDate" show-weeks="false"></datepciker> </div> <div> dt <span class="uneditable-input span2">{{dt | date:'dd.MM.yyyy' }}</span> dt <span class="uneditable-input span2">{{ dt }}</span> timestamp <span class="uneditable-input span2">{{ required.timestamp }}</span> </div> </div>
In this 2nd version, the timestamp is not updated when the date changes (it, like the watch $ watch, does not work).
Do you know how to make this work?
source share