AngularJS not validating email field in form

Posted by idipous on Stack Overflow See other posts from Stack Overflow or by idipous
Published on 2013-11-05T09:43:53Z Indexed on 2013/11/05 9:53 UTC
Read the original article Hit count: 163

Filed under:

I have the html below where I have a form that I want to submit to the AngularJS Controller.

<div class="newsletter color-1" id="subscribe" data-ng-controller="RegisterController">
  <form name="registerForm">
    <div class="col-md-6">
     <input type="email" placeholder="[email protected]" data-ng-model="userEmail" required class="subscribe">
   </div>
    <div class="col-md-2">
    <button data-ng-click="register()" class="btn btn-primary pull-right btn-block">Subsbcribe</button>
    </div>
  </form>
 </div>

And the controller is below

app.controller('RegisterController', function ($scope,dataFactory) {


$scope.users = dataFactory.getUsers();

$scope.register = function () {
    var userEmail = $scope.userEmail;
    dataFactory.insertUser(userEmail);
    $scope.userEmail = null;
    $scope.ThankYou = "Thank You!";
}
});

The problem is that no validation is taking place when I click the button. It is always routed to the controller although I do not supply a correct email. So every time I click the button I get the {{ThankYou}} variable displayed. Maybe I do not understand something.

© Stack Overflow or respective owner

Related posts about angularjs