为什么md-datepicker NOT在当前日期打开?

时间:2017-05-11 08:31:38

标签: javascript angularjs datepicker angular-material

您好我使用角料日期选择器。 小问题是,当我点击日期并打开日历时 - 它会打开并显示今天不是日期。但是有些遥远的日期。 如何在今天或至少在ng-model日期打开日历?

显示日期:

enter image description here

单击时

打开日历:

enter image description here

这里是html:

  <md-datepicker class="font" ng-model="vm.startDate"></md-datepicker>

获取模型:

     vm.startDate = new Date();

提前感谢您的帮助。

更新: 注意到了奇怪的行为:

CASE1: 当我滚动页面和日历几乎在页面顶部时:

enter image description here

当我打开日历时,它会显示当前日期:

enter image description here

CASE2: 同样但当datepicker在底部页面滚动时: 目前的日期,如果远远落后......

1 个答案:

答案 0 :(得分:3)

<强>样本

&#13;
&#13;
angular.module('datepickerBasicUsage', ['ngMaterial'])
.controller('AppCtrl', function ($scope) {
   var vm = this;
   vm.startDate = new Date();
});
&#13;
<!doctype html>
<html ng-app="datepickerBasicUsage">
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular-animate.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular-aria.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-material/1.0.4/angular-material.js"></script>
    <script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/t-114/assets-cache.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/angular-material/1.0.4/angular-material.css">
    <script src="app.js"></script>
  </head>
  <body>

  <div ng-controller="AppCtrl as vm" style='padding: 40px;'>
    <md-content>
      <h4>Standard date-picker</h4>
      <md-datepicker ng-model="vm.startDate" md-placeholder="Enter date"></md-datepicker>
    </md-content>
     </div>
  </body>
</html>
&#13;
&#13;
&#13;