0

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.

3
  • need little more code to help, its great if you can share the java script Commented May 27, 2016 at 9:51
  • You need to create the object signup{ spans: { name: "NameOfSpan" }}}; Commented May 27, 2016 at 9:54
  • if you really want to create a object call "spans" oki. Otherwise no use creating element like this Commented May 27, 2016 at 9:56

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Ohh .. I missed that. Thanks so much, that solved the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.