AngularJS:错误:md-datepicker的ng-model必须是Date实例。目前该模型是:数字

时间:2016-12-08 10:58:55

标签: javascript angularjs datepicker

我正在尝试使用日期(以毫秒为单位)过滤记录列表。我试过这个

HTML

<md-datepicker ng-model="myDateFilter" ng-change="dateFilter(myDateFilter)" md-placeholder="Enter date"></md-datepicker>

JS

$scope.myDateFilter = new Date().getTime();

    $scope.dateFilter = function (dt) {
      $scope.myDateFilter = new Date(dt).getTime();
    }
    $scope.dateFilter($scope.myDateFilter);

在控制台中收到此错误

angular.js:13920 Error: The ng-model for md-datepicker must be a Date instance. Currently the model is a: number
    at Array.<anonymous> (angular-material.js:28134)
    at ngModelWatch (angular.js:27810)
    at Scope.$digest (angular.js:17515)
    at Scope.$apply (angular.js:17790)
    at done (angular.js:11831)
    at completeRequest (angular.js:12033)
    at XMLHttpRequest.requestLoaded (angular.js:11966)

帮助我解决导致问题的原因。

0 个答案:

没有答案