我有下面的 html,我有一个要提交给 AngularJS 控制器的表单。
<div class="newsletter color-1" id="subscribe" data-ng-controller="RegisterController">
<form name="registerForm">
<div class="col-md-6">
<input type="email" placeholder="your@e-mail.com" 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>
控制器在下面
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!";
}
});
问题是当我单击按钮时没有进行验证。尽管我没有提供正确的电子邮件,但它总是被路由到控制器。因此,每次单击按钮时,都会显示 {{ThankYou}} 变量。也许我不明白一些事情。