Email already exists ...">

Ng-show expression ... how to debug it

I have the following code

<span ng-show="form.email.$error.unique">Email already exists</span>

      

This works correctly and I can see the span element if the email address entered in the "email" input field already exists in our db.

However, if I go into the chrome console. and then enter

form.email.$error

      

it says undefined.

I can enter

form.email 

      

and he shows me

โ€‹<input name=โ€‹"email" ng-model=โ€‹"model.email" required class=โ€‹"ng-dirty ng-invalid ng-invalid-unique">

      

So the question is, why can't I see the $ error in the Chrome console? this value definitely exists because angular reads it and based on the value it decides whether to show the range or not.

Edit :: Upon further reading documentation, I feel like a directive that checks if the email is valid or not ... sets the controller object to validity (4th parameter. $ SetValidity)

but somehow the UI is reading this $ error from the UI element.

so it's very confusing what the actual workflow is ... where the $ error is given and where it is being read from.

Can anyone please clarify this?

+3


source to share


2 answers


Download AngularJS Batarang Plugin for Chrome. Once enabled, you can check any item and the console $scope

will be the scope of the selected item.
Then you can check your mentioned span

and enter console $scope.form.email.$error.unique

and you will get the current value.

Alternatively, if you don't want to install this plugin (I would rather install it), you can get through javascript the current scope, for example angular.element(document.getElementById(...)).scope()

, and then check that scope.
(You can of course get the item in a different way and then fordocument.getElementById(...))



+4


source


Instead of debugging in the console, a useful technique is to simply output the variable as: {{form.email. $ error.unique}}. Place this above or below your input element and watch the value change dynamically as you type into it.



+3


source







All Articles