如何让我的 ui 按键在我的 Angular JS 应用程序中工作
How can I get ui-keypress working in my Angular JS app?
我的应用程序有一个登录表单,其中包含用户名、密码和单击登录按钮。但是,由于某种原因,我无法ui-keypress
登录按钮上工作。我正在使用ui-bootstrap
和ui-utils
. ui-utils
包含按键指令。
这是我到目前为止所拥有的:
我的登录部分:
<div id="loginForm">
<img id="logo" src="img/login_logo.png"/>
<alert ng-repeat="alert in alerts" type="alert.type" close="closeAlert($index)">
{{alert.msg}}
</alert>
<input type="text" id="username" ng-model="username" placeholder="Username"/>
<input type="password" id="password" ng-model="password" placeholder="Password"/>
<button type="button" id="loginBtn" class="btn btn-primary" ng-model="loginModel" ng-click="login()" ui-keypress="{13:'keypressLogin($event)'}">
Login
</button>
</div>
我的登录控制器:
ClutchControllers.controller("LoginController", [
'$scope',
'$http',
'$location',
'$cookieStore',
'Auth',
function($scope, $http, $location, $cookieStore, Auth) {
// Redirect if already logged in
if(Auth.isLoggedIn()) {
$location.path('/dashboard');
}
$scope.alerts = [];
$scope.closeAlert = function(index) {
$scope.alerts.splice(index, 1);
}
$scope.login = function() {
Auth.login({
username: $scope.username,
password: $scope.password
}, function(err, user) {
if(err) {
console.log(err);
$scope.alerts = [err];
} else {
console.log(user);
console.log(Auth.isLoggedIn());
//this this if you want to change the URL and add it to the history stack
$location.path('/dashboard');
}
});
}
$scope.keypressLogin = function($event) {
console.log($event);
console.log($scope.username);
}
}
]);
最后,我的应用路由:
angular.module('myApp', [
'ngCookies',
'ui.utils',
'ui.bootstrap',
'ui.utils',
'clutch.services',
'clutch.controllers'
])
.config(['$routeProvider', '$httpProvider', function($routeProvider, $httpProvider) {
$routeProvider
.when('/login', {
controller: "LoginController",
templateUrl: "partials/login.html",
auth: false
})
.when('/dashboard', {
controller: "DashboardController",
templateUrl: "partials/dashboard.html",
auth: true
})
.otherwise({ redirect: "/login" });
}]);
ClutchControllers = angular.module('clutch.controllers', ['ui.bootstrap']);
ClutchServices = angular.module('clutch.services', ['ngResource']);
只是一个想法,你为什么要使用 ui 键。恕我直言,在这种情况下,使用表单是更好的解决方案。考虑一下...
<form ng-submit="login()">
<input type="text"/>
<input type="password"/>
<button type="submit">Login</button>
</form>
胡乱猜测 - 你的button
上有ui-keypress
属性,而不是你的两个input
标签。
花了我一点时间在 jsfiddle 中重现您的所有依赖项:http://jsfiddle.net/tuv45/
相关文章:
- JQuery添加元素需要在我的js之前再次添加JQuery脚本
- 为什么不是'我的JS滑块正在工作
- 为什么我的JS不添加一个HTML类
- 使我的JS具有响应性
- 如何从我的js中分离错误和成功按钮
- 我的JS数组打印只显示结束值
- 有没有一种方法可以将我的JS函数排队到JSF事件队列中
- 我的JS在将ascii转换为字符串时添加了一个空格
- hasClass没有'我的js代码不起作用
- 可以'不要让我的.js在我的Dreamweaver文件中工作
- 为什么我的JS"如果“;语句的求值结果总是为false
- 应用<strong>标记到我的js.coffee文件中的字符串
- 如何将新的动态内容添加到我的JS代码中
- 为什么我的JS代码动作如此断断续续
- 为什么我的JS函数无法正常工作
- 提交时不触发我的 JS
- 使用 unity,我的 js 文件无法解决问题
- 即首先破坏我的 JS 脚本,然后我按 F12,它工作得很好
- 我的 JS 代码中的会话启动事件
- 我的js分页代码不起作用,完全不知道是什么原因造成的