错误:[ngModel:datefmt]预期`2015-05-29T19:06:16.693209Z`是一个日期 - 角 [英] Error: [ngModel:datefmt] Expected `2015-05-29T19:06:16.693209Z` to be a date - Angular

查看:1948
本文介绍了错误:[ngModel:datefmt]预期`2015-05-29T19:06:16.693209Z`是一个日期 - 角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Django的应用程序与休息的框架 ..

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

该应用程序接收到它与从服务器的JSON信息。其中的关键是 CREATED_TIME ...根据<$ C $此字段的值是格式C> ISO-8601 ,例如 2015-05-29T19:06:16.693209Z

The app receives it's info with json from the server.. One of the keys is created_time... The value of this field is format according to iso-8601, for example 2015-05-29T19:06:16.693209Z.

在客户端我有一个字段:

In the client I have a field:

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

但是,当数据到达我得到这个错误:

But when the data is arriving I get this error:

Error: [ngModel:datefmt] Expected `2015-05-29T19:06:16.693209Z` to be a date http://errors.angularjs.org/1.3.13/ngModel/datefmt?p0=2015-05-29T19%3A06%3A16.693209Z
at REGEX_STRING_REGEXP (angular.js:63)
at Array.<anonymous> (angular.js:19807)
at Object.ngModelWatch (angular.js:23289)
at Scope.$get.Scope.$digest (angular.js:14235)
at Scope.$get.Scope.$apply (angular.js:14506)
at done (angular.js:9659)
at completeRequest (angular.js:9849)
at XMLHttpRequest.requestLoaded (angular.js:9790)

我已经试过各种方法:(格式是完全一样的角的文档的说明...

I already tried everything :( the format is exactly as the instructions in the docs of angular...

推荐答案

这必须用角1.3+发生。 1.3+在病房NG-模式日期/时间输入需要是一个有效的日期对象,字符串重新日期presentation不再允许。您需要将字符串转换为日期对象( $ scope.created_time =新的日期(dateString)),并将其绑定到NG-模式。如果按照错误链接它有一个明确的说明有关该错误以及如何解决它。

This must be happening with angular 1.3+. 1.3+ on wards ng-model for date/time input needs to be a valid date object, string representation of date is no longer allowed. You need to convert string to date object ($scope.created_time = new Date(dateString)) and bind it to the ng-model. If you follow the error link it has a clear description about the error and how to resolve it.

像需要模型中的所有日期相关的输入是一个Date对象。如果模型是别的东西,这个错误将被抛出。角上不设置验证错误在这种情况下,因为这些误差被显示给用户,但错误的状态被不正确应用程序逻辑,而不是由用户引起的。

All date-related inputs like require the model to be a Date object. If the model is something else, this error will be thrown. Angular does not set validation errors on the in this case as those errors are shown to the user, but the erroneous state was caused by incorrect application logic and not by the user.

这篇关于错误:[ngModel:datefmt]预期`2015-05-29T19:06:16.693209Z`是一个日期 - 角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆