AngularJS ui-bootstrap: Datepicker not working in month mode

半城伤御伤魂 提交于 2019-12-11 03:41:20

问题


I am unable to use AngularJS' ui-bootstrap's datepicker in the month mode.

Here's a plunker.

Here's my template:

<html>

  <head>
    <link rel="stylesheet" href="style.css">
  </head>

  <body ng-app="TestApp">
    <div ng-controller="testController">

      {{dt}}
      <datepicker ng-model="dt.from" datepicker-mode="mode" min-mode="mode"></datepicker>
      <datepicker ng-model="dt.to" datepicker-mode="mode" min-mode="mode"></datepicker>
    </div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.25/angular.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.11.0/ui-bootstrap-tpls.min.js"></script>

    <script src="script.js"></script>
  </body>

</html>

Here's my JS:

var app = angular.module('TestApp', ['ui.bootstrap'])

app.controller('testController', function($scope) {
  $scope.dt = {to: '', from: ''};
  $scope.mode = 'month';

})

Whenever I click on a month, it changes to the 'day' mode. This is working fine in the day mode.


回答1:


Your code is working as-is with the latest version of Bootstrap UI (also requires a later version of Angular).

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.1/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.13.3/ui-bootstrap-tpls.js"></script>

Plunker

If upgrading is not an option then hard-coding min-mode to month also works.

<datepicker ng-model="dt.from" datepicker-mode="mode" min-mode="month"></datepicker>
<datepicker ng-model="dt.to" datepicker-mode="mode" min-mode="month"></datepicker>


来源:https://stackoverflow.com/questions/32334710/angularjs-ui-bootstrap-datepicker-not-working-in-month-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!