bootstrap 年份选择器不只选择年份

bootstrap year picker doesn't pick year only

我想做的是创建一个独立的年份选择器,不需要选择日期。但是 bootstrap 下面的配置让我深入了解,一旦我 select 年份,它就会显示月份和日期。但我只希望 selection 在我点击 year

时立即发生

javascript

$scope.formats = ['yyyy','dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
$scope.dateFormat = $scope.formats[0];
$scope.popup = {
    opened : false
};

$scope.open = function($event) {
    $event.preventDefault();
    $event.stopPropagation();
    $scope.popup.opened = true;
};

html

 <p class="input-group input-group-unstyled" style="margin-bottom: 0px">
<input type="text" class="form-control  input-sm" id="year" name="year"
       uib-datepicker-popup="{{dateFormat}}"
       ng-model="year"
       is-open="popup.opened"
       min-mode="year" datepicker-mode="'year'"
       close-text="Close"
   />
<span class="input-group-addon">
<i class="glyphicon glyphicon-calendar" ng-click="open($event)"></i>
</span>
</p>

您必须使用 'datepicker-options' 属性来传递选项,而不是元素属性。

<input type="text" class="form-control" ng-model="dt" 
   uib-datepicker-popup="{{format}}" datepicker-options="{{datepickerOptions}}"
   is-open="opened" ng-focus="open($event)"
  date-disabled="disabled(date, mode)" ng-required="true" close-text="Close">
</input>

$scope.datepickerOptions = {
  datepickerMode:"year",
  minMode:"year",
  minDate:"minDate",
  showWeeks:"false",
};

在此处查找文档:https://angular-ui.github.io/bootstrap/#/datepicker

希望对您有所帮助!

删除了 minMode:"'year'" 周围的单引号到 minMode:"year" 并解决了问题,奇怪的行为

varit05犯了一个小错误:

datepicker-options="{{datepickerOptions}}"

应该是:

日期选择器选项="datepickerOptions"

因为日期选择器选项已经在 angular 的 space 中。