AngularJS DatePicker在单击日期时不更新值

时间:2017-05-09 08:21:54

标签: javascript angularjs datepicker

我使用角度材料的angularjs的datepicker指令来创建日期输入的日历。

HTML

<md-datepicker ng-model='vm.endtoDate'></md-datepicker>

我面临的问题是,当我点击日历上的任何日期时,它都不会更新。

JS

 function SearchController($scope,$stateParams, $q, $log, httpRequests, $location, searchResults, header, icons,leafletData){
      var coordinates_selected;
      var vm = this;
      vm.endtoDate = new Date();
      var endto= console.log(JSON.stringify(vm.endtoDate,'end'));

P.S我不想使用监视功能监视更改的值,因为我后来想要将值存储在另一个变量中以进行时间搜索。

2 个答案:

答案 0 :(得分:1)

如果你不想要观察者或别的什么我建议你去参加日期选择器的更改活动,并使用该商店更改日期并在任何你想要的地方使用它

&#13;
&#13;
angular.module('datepickerBasicUsage', ['ngMaterial'])
.controller('AppCtrl', function ($scope) {
$scope.endtoDate = new Date();
$scope.selecteddate=function(){
 var endto= $scope.endtoDate;
 console.log(endto);
}
});
&#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" >
  
   
      <md-datepicker ng-model="endtoDate" ng-change="selecteddate()"></md-datepicker>
      
      
 
    
   
  </div>
  </body>
</html>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

&#13;
&#13;
angular.module('datepickerBasicUsage', ['ngMaterial'])
.controller('AppCtrl', function ($scope) {
$scope.endtoDate = new Date();
$scope.selecteddate=function(){
 var endto= $scope.endtoDate;
 console.log(endto);
}
});
&#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" >
  
   
      <md-datepicker ng-model="endtoDate" ng-change="selecteddate()"></md-datepicker>
      
      
 
    
   
  </div>
  </body>
</html>
&#13;
&#13;
&#13;