0

I have checked similar questions, and none of which apply to this situation.

I have an angular app, which I am attempting to validate manually, but I am having issues with this.

For simplification, I am only including the email field, the form fields are already validated in another function, and that function sets the $scope.regform.email.valid variable to true or False.

This works well enough when you deliberately enter the incorrect information into the fields, but if nothing is entered, and the register button is pressed, I would like to do an isDefined check, which doesn't seem to work.

//this is inside the function that runs is the register button is pressed.
//in this test case nothing has been entered in the email field when the register button is pressed.

email = angular.isDefined($scope.regform.email.valid);
console.log(email);

The isDefined function is meant to check whether the variable is defined or not, but if it is NOT defined, then the below error occurs, instead of 'email' evaluating to false.

TypeError: $scope.regform.email is undefined
Stack trace:
studyseshController/$scope.checkValid@http://localhost:8000/bundles/framework/js/app.js:17:13
anonymous/fn@http://localhost:8000/bundles/framework/js/angular.min.js line 239 > Function:2:147
bd[b]</<.compile/</</e@http://localhost:8000/bundles/framework/js/angular.min.js:284:195
Mf/this.$get</m.prototype.$eval@http://localhost:8000/bundles/framework/js/angular.min.js:148:351
Mf/this.$get</m.prototype.$apply@http://localhost:8000/bundles/framework/js/angular.min.js:149:55
bd[b]</<.compile/</<@http://localhost:8000/bundles/framework/js/angular.min.js:284:245
r.event.dispatch@https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js:3:10264
r.event.add/q.handle@https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js:3:8326
angular.min.js:123:218
AJT82
  • 60,574
  • 21
  • 115
  • 147
D_Breedt
  • 84
  • 2
  • 13
  • 1
    Maybe your answer here: http://stackoverflow.com/questions/27818331/what-is-the-benefit-of-angular-isdefined – Tai Le May 14 '17 at 05:38

1 Answers1

0

I found the issue, if the $scope.regform.email has not been defined, you can't even check whether an index within email has been defined. I changed the isDefined to first check if $scope.regform.email is defined before checking whether $scope.regform.email.valid was defined or not. This produced the result I was looking for.

D_Breedt
  • 84
  • 2
  • 13