1

私はHTML日付フィールドを持っています。MySQL データベースに日付を挿入する作成ページがあります。日付を取得して入力フィールドに戻す編集ページがあります。

<input id="dob" name="dob" type="date" placeholder="Enter date of birth" class="form-control" ng-model="user.dob"/>

JS

function loadUserById() {
        ApiService.getById($scope.id).then(function(response) {
            $scope.user = response.data[0];
            $scope.user.password1 = response.data[0].password;

            if($scope.user.dob) {
                var date = new Date($scope.user.dob);
                $scope.user.dob = moment(date).format("MM/DD/YYYY");
            }
        }, function(error) {
            console.log(error);
        });
    }

問題

このフィールドの日付を MySQL データベースに挿入し、フォーマットとしてYYYY-MM-DDフォーマットしています。次に、フォーマットしmm/dd/yyyyて、html 日付フィールドに設定しようとしています。

しかし、それはエラーを投げています。

angular.js:14642 Error: [ngModel:datefmt] http://errors.angularjs.org/1.6.5/ngModel/datefmt?p0=06%2F03%2F2018
at angular.js:88
at Array.<anonymous> (angular.js:25252)
at angular.js:29245
at m.$digest (angular.js:18202)
at m.$apply (angular.js:18480)
at l (angular.js:12501)
at XMLHttpRequest.s.onload (angular.js:12655)
4

1 に答える 1