2016-10-07 106 views
1

我有一個錯誤行爲的日曆。
只要有人打開它,就會選擇錯誤的日期。
我希望在打開時顯示當前日期。
這就是現在發生的事情:

enter image description heredatepicker中的當前日期



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 
}; 



我在做什麼錯?

+1

創建plunker演示再現問題。 – charlietfl

+0

你可以'console.log($ scope.maxDate)'? 'datepicker-options =「dateOptions」'工作嗎?它不應該是'datepicker-options =「{{dateOptions}}」' –

回答

1

在你的指令的配置你設置:

ng-model="systemDate" 

在你的代碼爲這個VAR設置: $ scope.systemDate = $過濾器( '日期')($ scope.dt,「DD -MM-YYYY');

你必須改變來自:

$scope.systemDate = $filter('date')($scope.dt , 'dd-MM-yyyy'); 

$scope.systemDate = $scope.today(); 
+0

這可以解決問題,但只能部分解決問題。我想要格式爲dd-MM-yyyy的日期。你能否更新你的答案,以便我可以接受它? :) –

相關問題