1

I am using AngularJD to insert data into mongoose db. My index file has a div:

<div id="links" ng-controller="loginController">
    <a ui-sref="login">Login</a>
    <a ui-sref="register">Register</a>
</div>

I use routing to redirect to this page. On my registration page, I'm trying to call a function on the click event of a button:

<form ng-app="login" name="myForm" ng-submit="addNew()" novalidate>
   <p>
      <input type="submit"
          ng-disabled="myForm.lname.$dirty && myForm.lname.$invalid ||
          myForm.fname.$dirty && myForm.fname.$invalid ||
          myForm.mail.$dirty && myForm.mail.$invalid ||
          myForm.pwd.$dirty && myForm.pwd.$invalid ||
          myForm.cpwd.$dirty && myForm.cpwd.$invalid">
    </p>
</form>

Here is my app.js file:

function loginController($scope)
{
    console.log('inside');
    $scope.addNew = function()
    {
        console.log('adding new entry');
        var newuser = {
            username: $scope.NewUname,
            firstname: $scope.fName,
            lastname: $scope.lName,
            email: $scope.mail,
            $password: $scope.pwd
        }

    }
}

When I debug, it is logging "inside" but not "adding new entry".

2
  • 3
    I don't see an ng-controller="loginController" wrapping the form. Are you omitting it here only? Commented Sep 17, 2014 at 13:43
  • Not sure what your issue is either without full context. Here is a working fiddle doing basically what you have: jsfiddle.net/smaye81/qn2vdufn Commented Sep 17, 2014 at 13:45

1 Answer 1

2

Your issue is that you're creating your ng-app on the form inside the register.html route template. The element that establishes the app with ng-app="login" should contain everything else. Thus your loginController, which would be instantiated via ng-controller="loginController", is not actually created because it is outside the angular application.

Edit

I just noticed that you said "inside" is logged, which actually means that the loginController is being instantiated. I'm guessing you've got another ng-app established in some other containing context around the links div. However, I still think your issue is that you're creating a new ng-app on the form itself in register.html. I'm pretty sure you can't nest an angular application inside another. Best case, this would be interrupting the loginController context inside the form (it's probably doing more/worse than that). One way or another I think that ng-app declaration is your problem.

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

Comments

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.