我在使用角度js登录表单在键盘上使用“输入按钮”时遇到问题。我知道之前有人问这个问题,但我相信我的问题有点不同,因为我几乎尝试了所有写在stackoverflow问题上的问题。
所以,我只想在键盘上使用回车键点击输入并提交表单。
这是login html:
<!-- BEGIN LOGIN FORM -->
<form ng-submit="loginCtrl.login()" class="login-form">
<h3 class="form-title">Sign In</h3>
<div class="alert alert-danger display-hide">
<button class="close" data-close="alert"></button>
<span>
Enter any username and password. </span>
</div>
<div class="form-group">
<!--ie8, ie9 does not support html5 placeholder, so we just show field title for that-->
<label class="control-label visible-ie8 visible-ie9">Username</label>
<input class="form-control form-control-solid placeholder-no-fix" type="text" autocomplete="off" placeholder="Company/username"
ng-model="loginCtrl.username" name="username"/>
</div>
<div class="form-group">
<label class="control-label visible-ie8 visible-ie9">Password</label>
<input class="form-control form-control-solid placeholder-no-fix" type="password" autocomplete="off" placeholder="Password"
ng-model="loginCtrl.password" name="password"/>
</div>
<div class="form-actions">
<input type="submit" class="btn btn-success uppercase" value="Login">
</div>
</form>
<!-- END LOGIN FORM -->
这是我的登录信息:
self.login = function() {
var result = self.username.split("/");
var account = result[0];
var userId = result[1];
UserService.login(userId, self.password,account).then(function(user) {
self.userAccount = user;
$state.go('home');
}, function(err) {
alert("Authentication failure: Please check your credentials. ")
});
我将用户名称为“companyName / Username”,因此它类似于: 亚马逊/ bigboby
答案 0 :(得分:1)
我很确定您的问题是由my_global_logger->log("hello");
标记引起的:
<button>
答案可在documentation:
中找到您可以使用以下两种方法之一来指定在提交表单时应调用的javascript方法:
表单元素上的
<button class="close" data-close="alert"></button>
指令 对于提交类型的第一个按钮或输入字段的
ngSubmit
指令(输入[type = submit])
请注意有关如何在第一个按钮上查找ng-click处理程序的注释。当您按 ENTER 提交表单时,Angular会查看表单并看到该按钮。它会在该按钮上执行ngClick
处理程序(如果有的话)。
如果在按钮上包含ng-click
属性,则可以阻止该属性并让它找到实际的提交按钮:
type