我有一个行为不对的日历
一旦有人打开它,就会选择错误的日期。
我想在打开时显示当前日期。
这就是现在发生的事情:
HTML:
<p class="input-group">
<input id="dataClass" type="text" name="input"
placeholder="gg-mm-aaaa"
tooltip="Inserire una data nel formato gg-mm-aaaa"
tooltip-placement="bottom" class="form-control input-sm"
custom-datepicker-pattern="{{customDatePattern}}"
datepicker-popup="{{formatoDataDatePicker}}"
show-button-bar="false" ng-model="systemDate"
is-open="status.opened" min-date="'01-01-1900'" max-date="maxDate"
datepicker-options="dateOptions"
date-disabled="disabled(date, mode)" ng-required="true"
close-text="Chiudi" current-text="Oggi" />
<span class="input-group-btn">
<button type="button" class="btn btn-primary btn-sm"
ng-click="open($event)" tooltip="Cambia data timbro"
tooltip-placement="right">
<i class="fa fa-calendar"></i>
</button>
</span>
</p>
JS:
$scope.today = function() {
$scope.dt = new Date();
};
$scope.today();
$scope.today = new Date();
$scope.dt = $filter('date')($scope.today , 'yyyy-MM-dd');
$scope.systemDate = $filter('date')($scope.dt , 'dd-MM-yyyy');
$scope.clear = function () {
$scope.dt = null;
};
$scope.toggleMin = function() {
$scope.minDate = $scope.minDate ? null : new Date();
};
$scope.toggleMin();
$scope.toggleMax = function() {
$scope.maxDate = $scope.maxDate ? null : new Date();
};
$scope.toggleMax();
$scope.maxDate = $filter('date')($scope.today , 'yyyy-MM-dd');
$scope.open = function($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.status.opened = true;
};
$scope.dateOptions = {
formatYear: 'yy',
startingDay: 1
};
我做错了什么?
答案 0 :(得分:1)
在您的指令配置中,您已设置:
ng-model="systemDate"
在为此var设置的代码中: $ scope.systemDate = $ filter(&#39; date&#39;)($ scope.dt,&#39; dd-MM-yyyy&#39;);
你必须改变:
$scope.systemDate = $filter('date')($scope.dt , 'dd-MM-yyyy');
到
$scope.systemDate = $scope.today();