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

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

问题描述

我正在使用角度应用程序与 Django rest-framework ..

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

该应用程序从服务器收到json信息。其中一个关键是 created_time ...该字段的值是根据 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模型输入需要是有效的日期对象,不再允许字符串表示日期,您需要将字符串转换为日期对象( $ scope.created_time = new Date(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对象。如果模型是别的,这个错误将被抛出。在这种情况下,Angular没有设置验证错误,因为这些错误向用户显示,但错误的状态是由错误的应用程序逻辑引起的,而不是由用户造成的。

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天全站免登陆