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

前端 未结 8 700
爱一瞬间的悲伤
爱一瞬间的悲伤 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:30

    In addition to PSL's answer. This is how to override angular 1.3+ requirements to be a Date object.

    app.directive('dateFormat', function() {
      return {
        require: 'ngModel',
        link: function(scope, element, attr, ngModelCtrl) {
          //Angular 1.3 insert a formater that force to set model to date object, otherwise throw exception.
          //Reset default angular formatters/parsers
          ngModelCtrl.$formatters.length = 0;
          ngModelCtrl.$parsers.length = 0;
        }
      };
    });
    

    It can be used with AngularFire $firebaseObject and works fine with $bindTo 3-way binding. No need to extend $firebaseObject service. It works in Ionic/cordova applications.

    Working example on jsfiddle

    Based on this answer

提交回复
热议问题