user6039980 user6039980 - 6 months ago 16
AngularJS Question

Ionic: Error: undefined is not an object

I'm trying to check some signup fields using the following code:

$scope.signup = function()
{

if ($scope.signup.spans.name)
return;


This is the html code that refers to
$scope.signup.spans.name
:

<span ng-model="signup.spans.name" style="padding: 2px 0 2px 16px; color: red;" ng-if="!check_name()">Please type a valid name</span>


However after testing the app, I get stuck at the error:


Error: undefined is not an object (evaluating
'$scope.signup.spans.name') signup


So what's wrong with my code? is there any possibility to fix that?

I need some help.

Thanks in advance.

Answer

Where you initialise the controller you have to define $scope.signup like this:

$scope.signup = {
    spans: {}
}

ngModel won't automatically create object variables for you