1

Ze HTML:

<body ng-app="ReporterApplication" ng-controller="BootstrapController as bootstrap">
 <div><% boostrap.user %></div>
 <div id="pagePreloader"></div>
 <div ng-if="!bootstrap.user.logged" ng-controller="LoginController as login" class='site-wrapper-login'>
 <form role="form" name="login" class="form-login">
 <div class="logo-wrapper">
 <img class="logo" src="/resources/images/logo.png">
 <div class="logo-text">
 <div class="reporter">Reporter</div>
 <div class="application">Internal Application</div>
 </div>
 </div>
 <div class="icon-input large">
 <i class="icon fa fa-user"></i>
 <input ng-model="login.username" type="text" name="reg_username" class="input-text" id="username" placeholder="Enter Username">
 </div>
 <div class="icon-input large">
 <i class="icon fa fa-lock"></i>
 <input ng-model="login.password" type="password" name="reg_password" class="input-text" id="password" placeholder="Enter Password">
 </div>
 <button class="button full large" ng-click="login.submit()">Login</button>
 </form>
 </div>

and ze rezpective JS:

Application.controller('LoginController', ['$scope', 'ServerActions', function($scope, ServerActions)
{
 console.log('WE LOGIN!');
 var login = this;
 login.username = "";
 login.password = "";
 login.submit = function () {
 console.log('SUBMIT');
 ServerActions.fetchData('login.action', {username: login.username, password: login.password}).then(
 function (response) {
 console.log('SUBMIT SUCCESS');
 }
 );
 }
}]);

For some reason my submit function doesn't get called. Why is that? What am i doing wrong? Why does god hate me!?!??! Is there something about controllers stacking that interferes with the way i expect the code to work?

asked Sep 23, 2015 at 11:23
3
  • 2
    You should define properties and methods on $scope like: $scope.submit = function(){... Commented Sep 23, 2015 at 11:24
  • Try using post request for password Commented Sep 23, 2015 at 11:27
  • @Grievoushead Using $scope would indeed make the submit function trigger, but doesn't address the issue at hand Commented Sep 23, 2015 at 11:35

1 Answer 1

3

<form name=login> this is actually creating a global variable name from your form element, therefore it is conflicting with the name you've given to your controller. Either remove the name from the form:

<div ng-controller="LoginController as login" class='site-wrapper-login'>
 <form role="form" class="form-login">
 </form>
</div>

Or else rename your controller as variable:

<div ng-controller="LoginController as loginCtrl">

Example Fiddle

answered Sep 23, 2015 at 11:33
Sign up to request clarification or add additional context in comments.

1 Comment

yes indeed. many thanks for such a good response my good sir!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.