0

シンプルなフォームを作成しています。このフォームは誕生日フィールドを取得します。日付を選択して保持できます。しかし、ページをリロードするとエラーが発生します

Error: [ngModel:datefmt] Expected `2015-03-06T23:00:00.000Z` to be a date

私はそれを解決する方法を知っています。user.date_birthday を日付に変換する必要があります。だから私はこれを試しました。

'use strict';

angular.module('TheNameApp')
 .controller('SettingsCtrl', function ($scope, User, Auth) {

$scope.user = User.get();
$scope.errors = {};

console.log($scope.user); // display the resource
console.log($scope.user.date_birthday); //undefined

$scope.changeInformations = function(form) {
  $scope.infos_submitted = true;
  if(form.$valid) {
    Auth.changeInformations({
      gender: $scope.user.gender,
      city: $scope.user.city,
      country: $scope.user.country,
      talent: $scope.user.talent,
      date_birthday: $scope.user.date_birthday,
      user_name: $scope.user.user_name,
      email: $scope.user.email })
    .then( function() {
      $scope.infos_message = 'Done.'
    })
    .catch( function(err) {
      err = err.data;
      $scope.errors = {};

      // Update validity of form fields that match the mongoose errors
      angular.forEach(err.errors, function(error, field) {
        form[field].$setValidity('mongoose', false);
        $scope.errors[field] = error.message;
      });
    });
  }
};

.html

    <div class="form-group">
      <label>Birthday</label>

      <input type="date" name="date_birthday" class="form-control" ng-model="user.date_birthday"/>
    </div>

user.date_birthday は定義されていませんが、$scope.user で確認できます。次のステップでこれが必要です

$scope.user.date_birthday = new Date($scope.user.date_birthday);

自分の属性が表示されないのはなぜですか? どうすればこれを解決できますか?

4

1 に答える 1