【问题标题】:getting "read property 'length' of undefined" when try to enter date尝试输入日期时获取“未定义的读取属性'长度'”
【发布时间】:2018-11-06 04:40:38
【问题描述】:

你能告诉我为什么会出现这个错误吗?

angular.js:12798 TypeError: Cannot read property 'length' of undefined
    at parseDateString (VM651 ui-bootstrap-tpls-2.5.0.js:3037)
    at Array.parseDate (VM651 ui-bootstrap-tpls-2.5.0.js:3062)
    at NgModelController.$$parseAndValidate (VM647 angular.js:25837)
    at NgModelController.$commitViewValue (VM647 angular.js:25827)
    at VM647 angular.js:25970
    at ChildScope.$eval (VM647 angular.js:16374)
    at ChildScope.$apply (VM647 angular.js:16474)
    at NgModelController.$$debounceViewValueCommit (VM647 angular.js:25969)
    at NgModelController.$setViewValue (VM647 angular.js:25941)
    at HTMLInputElement.listener (VM647 angular.js:22200)
(anonymous) @ angular.js:12798
(anonymous) @ angular.js:9545
$apply @ angular.js:16479
$$debounceViewValueCommit @ angular.js:25969
$setViewValue @ angular.js:25941
listener @ angular.js:22200
dispatch @ jquery.js:5183
elemData.handle @ jquery.js:4991

实际上我试图在不使用“datepicker”的情况下输入日期然后我得到这个错误为什么。如何解决这个错误

重现此错误的步骤

  1. 运行应用程序。第一个日期字段为空。我刚刚在里面输入了1,然后我会收到这个错误,为什么?

http://plnkr.co/edit/ZG4Inotn7EtVZ5QbCsMH?p=preview

$scope.changedate =function(){
    console.log('asda')
  }

我也没有得到改变的事件。

我正在从这里制作日期选择器 https://angular-ui.github.io/bootstrap/#!#datepicker

【问题讨论】:

    标签: javascript angularjs angular-ui-bootstrap angularjs-bootstrap


    【解决方案1】:

    您已选择提供一组备用日期格式,但尚未将其正确映射到 HTML 中。

    具体来说,

    <input type="text" ng-change='changedate()' class="form-control" uib-datepicker-popup="{{format}}" ng-model="x.name" is-open="x.opened" datepicker-options="dateOptions" ng-required="true" close-text="Close" alt-input-formats="formats" />
    

    您将 alt-input-formats 映射到未定义的 altInputFormats

    Here's an updated Plunker.

    【讨论】:

    • 当用户从日期选择器中选择日期时,我可以得到任何事件吗?
    • 您的意思是在您的changedate() 处理程序中接收Date 值作为参数?当然。只需确保您在 HTML 中传递它(即ng-change="changedate(x.name)"),然后在changedate() 中使用它执行您需要的操作。
    猜你喜欢
    • 2019-08-08
    • 2019-02-05
    • 1970-01-01
    • 1970-01-01
    • 2019-02-24
    • 1970-01-01
    • 1970-01-01
    • 2011-11-01
    • 1970-01-01
    相关资源
    最近更新 更多