我在尝试处理的 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/