簡體   English   中英

Angular UI引導日期選擇器

[英]Angular UI bootstrap datepicker

我正在使用Angular UI bootstrap的datepicker,並且當我以編程方式更改日期時視圖不變,當我在Novembre中並且以編程方式將日期更改為12月2日時,日期更改但視圖仍然固定在11月,這是我編寫下一個日期按鈕的方式。

$scope.right=function(){
    if($scope.viewmodel.timeResolution=='yearly')
        $scope.dt.setFullYear($scope.dt.getFullYear()+1);
    else if($scope.viewmodel.timeResolution=='monthly')
        $scope.dt.setMonth($scope.dt.getMonth()+1);
    else if($scope.viewmodel.timeResolution=='daily') {
        $scope.dt.setDate($scope.dt.getDate() + 1);
    }
    $scope.changedValue();
};

HTML:

 <uib-datepicker ng-model="dt" id="dp" datepicker-mode="mode" init-date="initDate" show-weeks=false max-mode="maxMode"  min-date="minDate" max-date="maxDate" min-mode="minMode" class="well well-sm"  ng-change="changedValue(viewmodel.dt)"></uib-datepicker>

每當我在datepicker上以編程方式更改日期時,如何模擬刷新視圖?

您需要再次轉換為日期。 函數集...僅返回時間戳:

$scope.right=function(){
    if($scope.viewmodel.timeResolution=='yearly')
        $scope.dt = new Date($scope.dt.setFullYear($scope.dt.getFullYear()+1));
    else if($scope.viewmodel.timeResolution=='monthly')
        $scope.dt = new Date($scope.dt.setMonth($scope.dt.getMonth()+1));
    else if($scope.viewmodel.timeResolution=='daily') {
        $scope.dt = new Date($scope.dt.setDate($scope.dt.getDate() + 1));
    }
    $scope.changedValue();
};

為了使您更好地了解日期日期,您應該查看.js時刻

http://momentjs.com/

它使您可以輕松地以最少的問題創建,格式化,添加和減去日期。 使用默認的date.set函數可能會導致很多問題。

我使用沒有問題的瞬間進行了這樣的設置

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM