AngularUI Bootstrap Datepicker设置最小日期

时间:2014-08-29 16:12:04

标签: javascript angularjs angularjs-scope angular-ui-bootstrap

我正在运行最新的AngularUI Bootstrap,并且我有一个Datepicker,当它被一个按钮点击打开时会启用。

我已经尝试并搜索了如何禁用点击日期的答案,我希望最低日期为2013年1月1日 - 意味着2012年12月31日及更早的日期将无法选择。

以下是我的代码

ANGULARJS

                    $scope.today = function() {
                        $scope.dt = new Date();
                    };
                    $scope.today();

                    $scope.clear = function () {
                        $scope.dt = null;
                    };
                    // Disable weekend selection
                    $scope.disabled = function(date, mode) {
                        //return ( mode === 'day' && ( date.getDay() === 0 || date.getDay() === 6 ) );
                    };

                    $scope.toggleMin = function() {
                        $scope.minDate = $scope.minDate ? null : new Date();
                    };
                    //$scope.toggleMin();

                    $scope.open = function() {
                        $timeout(function() {
                            $scope.opened = true;
                            $scope.minEndDate = '2013-01-01';
                        });
                    };


                    $scope.dateOptions = {
                        formatYear: 'yy',
                        startingDay: 1
                    };
                    $scope.initDate = new Date('2016-15-20');
                    $scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
                    $scope.format = $scope.formats[0];

HTML

<input type="text" class="form-control input--text" datepicker-popup="{{format}}" ng-model="newperson.dob" is-open="$parent.opened" min="minEndDate" max-date="'2015-06-22'" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" close-text="Close" />
                    <button type="button" class="datepicker-btn" ng-click="open()"><i class="fa fa-calendar"></i></button>

1 个答案:

答案 0 :(得分:0)

属性为min-date,您只有min

<input type="text" class="form-control input--text" datepicker-popup="{{format}}" ng-model="newperson.dob" is-open="$parent.opened" min-date="minEndDate" max-date="'2015-06-22'" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" close-text="Close" />
                    <button type="button" class="datepicker-btn" ng-click="open()"><i class="fa fa-calendar"></i></button>