Not sure why you are using type="submit" here since ultimately your are going to authenticate via $http but, that issue aside, you are setting your login to the result of calling the authenticate function hence as soon as the controller is loaded it is executing the function.
Try this: http://plnkr.co/edit/S2on4K4AxMNGYERCiiwk?p=preview On Thursday, April 3, 2014 8:42:53 PM UTC-6, Billy Figueroa wrote: > > Hi this is a bit of a weird error. I m hoping someone can help me. > > I am working on an auth service where I want to authenticate a user once > they submit their form. For some reason the code is executing with out me > submitting the form > > Here is the plunker > > http://plnkr.co/edit/xZ74qGbitXmpYxqsbCm2 > > You can see in the index.html file I have the form with the ng-submit > directive to call the login function in the Controller which injects my > "AuthFactory" service. If you run the plunker and look at the console you > will see that it displays the login data... > > Object { username="Username", password="Password"} > > from this line in the auth service... > > console.log(loginData); > > Please help me understand why this code is executing with out me > submitting my form. I only want this code to execute when I submit my form > > I do understand a bit how promises work so I am not sure if the problem > lies there or its something else. > -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
