Angular material datepicker不选择我选择的日期

时间:2016-09-23 14:36:47

标签: javascript angularjs datepicker angular-material

Angular material datepicker不选择我选择的日期而是我总是在angularjs控制器中获得sysdate,即使我选择了另一个日期。我做错了什么?

我的控制器:

angular.module('MyApp')
    .controller('MyController', ['$scope', 'growl',
        'modalService', 'moment',
        '$uibModal', '$log', 
        function ($scope, growl, modalService, 
                moment, $uibModal, $log) {

                                $scope.initDate = new Date();

                                $scope.printDate = function() {
                                    console.log($scope.initDate);
                                }
        }]);

我的观点

<md-datepicker ng-model="initDate" md-placeholder="Select a date"
           ng-change="printDate()"
           md-min-date="minDate"
           md-date-filter="disabledWeekned">
         </md-datepicker>

1 个答案:

答案 0 :(得分:-1)

如果可以的话,也许可以尝试将你的日期选择器应用于模型:

$scope.model = {};
$scope.model.initDate = new Date();

<md-datepicker ng-model="model.initDate" md-placeholder="Select a date"
       ng-change="printDate()"
       md-min-date="minDate"
       md-date-filter="disabledWeekned">
     </md-datepicker>

希望有帮助=)