AngularJS - Initializing DATE input

后端 未结 1 1089
我在风中等你
我在风中等你 2021-01-23 08:30

I have an application in which there are several date fields that need to accept values from the user as well as from the database.

I found this solution but still get

相关标签:
1条回答
  • 2021-01-23 08:43

    Documentation from Angularjs:

    All date-related inputs like require the model to be a Date object. If the model is something else, this error will be thrown


    You should bind to date-type input with only date-type data. By new Date(parameter) will generate a date object of your data.

    angular.module("app", [])
      .controller("myCtrl", function($scope, $filter) {
        //$scope.testDate = $filter('date')(Date.now(), 'yyyy/MM/dd');
        $scope.testDate = new Date('2017-05-03');
      });
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
    <div ng-app="app" ng-controller="myCtrl">
      <input type="date" ng-model="testDate">
    </div>

    0 讨论(0)
提交回复
热议问题