2016-09-26 68 views
0

我正在嘗試將角度js datepicker注入到我的項目中。我根據文件完成。但沒有看到可見日期選擇器。 我創建了一個plnkr plnkrAngular Datepicker minDate和maxDate不工作

<!DOCTYPE html> 
<html ng-app="plunker"> 

    <head> 
    <meta charset="utf-8" /> 
    <title>AngularJS Plunker</title> 
    <script>document.write('<base href="' + document.location + '" />');</script> 
    <link rel="stylesheet" href="style.css" /> 
    <link rel="stylesheet" href="https://rawgit.com/g00fy-/angular-datepicker/master/app/styles/bootstrap.css"> 
    <link rel="stylesheet" href="https://rawgit.com/g00fy-/angular-datepicker/master/dist/angular-datepicker.css" /> 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js"></script> 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.4.1/moment-timezone-with-data.js"></script> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script> 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.6.0/ui-bootstrap-tpls.min.js"></script> 
    <script src="https://rawgit.com/g00fy-/angular-datepicker/master/app/scripts/datePicker.js"></script> 
    <script src="https://rawgit.com/g00fy-/angular-datepicker/master/app/scripts/datePickerUtils.js"></script> 
    <script src="https://rawgit.com/g00fy-/angular-datepicker/master/app/scripts/dateRange.js"></script> 
    <script src="https://rawgit.com/g00fy-/angular-datepicker/master/app/scripts/input.js"></script> 
    <script src="app.js"></script> 

    </head> 

    <body ng-controller="MainCtrl"> 
    <input class="form-control" date-time ng-model="DateOfbirth" max-date="today" view="date" timezone="UTC" format="yyyy-MM-dd HH:mm"> 
    </body> 

</html> 

參考文件。 here

回答

0

我有同樣的問題。

嘗試升級角版本1.5.x的

一些是最大/最小日期需要的功能不包括在最低

角版本。

0

我通過添加自定義$watch解決了我的問題。

$scope.$watch('addUserProfileData.DateOfbirth', validate_dateOfbirth); 

    function validate_dateOfbirth() { 

     if ($scope.addUserProfileData.DateOfbirth != "") { 

      var selectedDate = moment($scope.addUserProfileData.DateOfbirth.toISOString()).format('DD/MM/YYYY'); 
      var current_date = moment(moment().toISOString()).format('DD/MM/YYYY'); 

      var momentA = moment(selectedDate,"DD/MM/YYYY"); 
      var momentB = moment(current_date,"DD/MM/YYYY"); 

      if (momentA >= momentB) { 

       $scope.addUserProfileForm.DateOfbirth.$setValidity("endBeforeStart", false); 
      } else { 
       $scope.addUserProfileForm.DateOfbirth.$setValidity("endBeforeStart", true); 
      } 
     } 

    } 
相關問題