Angularjs ng单击“不处理提交”按钮
我正在学习如何使用AngularJS,但我无法使用自定义的Angularjs ng单击“不处理提交”按钮,angularjs,Angularjs,我正在学习如何使用AngularJS,但我无法使用自定义的ng click功能。我要做的是启动一个$http.post请求,该请求包含来自我表单的数据($scope.email,$scope.username,$scope.password)。到目前为止,我只尝试传递电子邮件,但当我单击提交按钮时,什么也没有发生(没有触发POST请求,我正在用firebug检查这一点)。我尝试将其直接作为$scope.email或变量传递(如下所示) 我有一个主页(index.html),它使用ng视图使用ng
ng click
功能。我要做的是启动一个$http.post
请求,该请求包含来自我表单的数据($scope.email
,$scope.username
,$scope.password
)。到目前为止,我只尝试传递电子邮件,但当我单击提交按钮时,什么也没有发生(没有触发POST请求,我正在用firebug检查这一点)。我尝试将其直接作为$scope.email
或变量传递(如下所示)
我有一个主页(index.html),它使用ng视图
使用ngRoute
加载html。这是路线代码:
.when('/register', {
templateUrl: 'views/register.html',
controller: 'RegisterCtrl'
})
这是我的register.html:
<div class="container">
<div class="col-xs-2 col-sm-3 col-md-4"></div>
<div class="col-xs-8 col-sm-6 col-md-4">
<h1>Sign Up:</h1>
<form>
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" id="email" ng-model="email">
</div>
<div class="form-group">
<label for="username">Username:</label>
<input type="text" class="form-control" id="username" ng-model="username">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd" ng-model="password">
</div>
<button type="submit" class="btn btn-primary col-xs-5" ng-click="register">Sign up</button>
<div class="col-xs-2"></div>
<button class="btn btn-info col-xs-5">Go to log in</button>
</form>
</div>
</div>
它应该有函数
()
方括号来调用函数,比如ng click=“register()”
或者,为了获得更好的方式,而不是使用ng单击表单上的
,您可以将其替换为ng提交
指令
标记
<form name="myForm" ng-click="register()">
...fields here..
<button type="submit" class="btn btn-primary col-xs-5">Sign up</button>
<div class="col-xs-2"></div>
<button class="btn btn-info col-xs-5">Go to log in</button>
</form>
…这里的田地。。
注册
登录
此外,您需要为表单指定表单名称,以便在表单验证中获得更好的控制器
<form name="myForm" ng-click="register()">
...fields here..
<button type="submit" class="btn btn-primary col-xs-5">Sign up</button>
<div class="col-xs-2"></div>
<button class="btn btn-info col-xs-5">Go to log in</button>
</form>