为什么我在AngularJS中的日期输入字段会引发类型错误? [英] Why is my date input field in AngularJS throwing type error?

查看:107
本文介绍了为什么我在AngularJS中的日期输入字段会引发类型错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我向用户显示填充的,可编辑的表单时(而不是在用户输入数据并提交时),就会发生错误.数据来自MySQL,基于以下服务中的REST/JSON:

The error occurs when I display the populated, editable form to the user (not when a user enters in data and submits). The data is coming from MySQL over REST/JSON in the service shown below:

HTML:

<input class="form-control" type="date" name="dateInput" id="dateOfBirth" 
                   ng-model="user.dateOfBirth">

CCONTROLLER:

CCONTROLLER:

.controller('EditCtrl', function ($scope, $routeParams, UserDetail, $window) {
        $scope.user = UserDetail.find({}, {'id': $routeParams.id});
}

服务:

service.factory('UserDetail', function ($resource) {

    return $resource(
        'http://localhost:8080/ClearsoftDemoBackend/webresources/clearsoft.demo.users/:id',
        {id: '@id'},
    {
    find: {method: 'GET'},

    });
});

错误:

错误:[ngModel:datefmt]预期2010-05-13T00:00:00-04:00为日期

Error: [ngModel:datefmt] Expected 2010-05-13T00:00:00-04:00 to be a date

推荐答案

这是因为根据Angular的规定,该日期不是有效日期. 查看input [date]上的文档以获取有关他们的注释日期验证.要使其成为日期,其格式应为YYYY-MM-DD.

Its because that is not a valid date according to Angular. Check out the doc on input[date] for their note on date validation. For it to be a date it should be in the format of YYYY-MM-DD.

这篇关于为什么我在AngularJS中的日期输入字段会引发类型错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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