javascript - 无法读取未定义的属性 'toLowerCase'

标签 javascript jquery angularjs

我在尝试处理的 Angular 错误消息时遇到问题。我试图确保确认电子邮件的不区分大小写不适用于初始电子邮件地址。

在我的 Controller 中,我使用了 toLowerCase() 过滤器......除了控制台无法识别这一点并给我一条错误消息这一事实。

我的前端代码是

input-md{ type: "email", "ng-model" => "vm.form.email_confirmation", required: true, 'must-match' => 'register_form["vm-form-email"]', 'match-case-insensitive' => true, 'ng-hide' => 'vm.form.validated_email', autocapitalize: 'off' }

和我的 Controller (以及最终问题所在)

getMatchValue = ->
  match = matchGetter($scope)
  if (angular.isObject(match) and match.hasOwnProperty('$viewValue'))
    match = match.$viewValue
  match

$scope.$watch getMatchValue, ->
  ctrl.$$parseAndValidate()
  return

ctrl.$validators.mustMatch = ->
  match = getMatchValue()

  if $attrs.matchCaseInsensitive
    ctrl.$viewValue.toLowerCase() is match.toLowerCase()
  else
    ctrl.$viewValue is match
return

如果有人能看一下这个,我将不胜感激!

最佳答案

您应该确保您的对象不是未定义,您可以使用angular.isDefined .

确保您的对象不会未定义

if (angular.isDefined(ctrl.$viewValue)){
    //Your Code
}

关于javascript - 无法读取未定义的属性 'toLowerCase',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38752074/

相关文章:

javascript - 为什么 0.86%1 不是零而是 0.86,因为 0.86/1 的余数为 0?

javascript - 如何停止所有当前正在播放的 MediaElement 播放器?

javascript - 使用 javascript 更改 cssRules 在客户端上不是永久性的,在部分回发后被清除

php - 文件上传成功后成功消息变为取消消息

javascript - 在javascript中使用相同的id获取不同的值

javascript - module.exports 的意外简写

javascript - Highcharts图表宽度动态显示大小

angularjs - Angular e2e/Karma - 在 Suite block 之前?

javascript - 允许用户使用angularjs在输入框中只输入正数

angularjs - Angular : how to build a directive to watch a text field