簡體   English   中英

無法讀取未定義的屬性“ toLowerCase”

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM