[英]Cannot read property 'toLowerCase' of undefined
我在尝试处理角度错误消息时遇到麻烦。 我试图确保确认电子邮件的大小写不敏感不适用于初始电子邮件地址。
在我的控制器中,我使用的是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' }
和我的控制器(最终是问题所在)
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
如果有人可以看一下,我将不胜感激!
您应该确保您的对象不是undefined
,可以使用angular.isDefined 。
确保您的对象不会被undefined
if (angular.isDefined(ctrl.$viewValue)){
//Your Code
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.