繁体   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