Error: [ngModel:datefmt] Expected `2015-05-29T19:06:16.693209Z` to be a date - Angular

前端 未结 8 652
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-29 07:10

I\'m working on angularapplication with Django with rest-framework..

The app receives it\'s info with json from the server.. O

相关标签:
8条回答
  • 2020-11-29 07:50

    Create a simple directive that converts the model value:

    HTML:

    <input date-input type="time" ng-model="created_time">
    

    Directive:

    app.directive('dateInput', function(){
        return {
            restrict : 'A',
            scope : {
                ngModel : '='
            },
            link: function (scope) {
                if (scope.ngModel) scope.ngModel = new Date(scope.ngModel);
            }
        }
    });
    
    0 讨论(0)
  • 2020-11-29 07:51

    If you need to update all dates in Array with Objects

    var data = [
      { id: "1" , birthday: "2016-01-20T11:24:20.882Z"},
      { id: "2" , birthday: "2016-01-20T11:24:20.882Z"},
      { id: "3" , birthday: "2016-01-20T11:24:20.882Z"},
    ];
    
      function convertDataStingToObject (data) {
        for(var i=0; i < data.length; i++ ){
          console.log('string: ' + data[i].birthday);
          data[i].birthday = new Date(data[i].birthday);
          console.log('updated: ' + data[i].birthday);
          console.log(typeof(data[i].birthday));
        }
    
        return data;
      }
    
    convertDataStingToObject(data);
    
    0 讨论(0)
提交回复
热议问题