我有一个表格来收集用户的注册详细信息,定义如下:
<form class="m-t-xl" ng-submit="signup(user)" novalidate>
<div class="form-group">
<input type="text" class="form-control" placeholder="Name" required="" ng-model="user.name">
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Email" required="" ng-model="user.email">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Company" required="" ng-model="user.company">
</div>
<div class="form-group">
<input type="password" class="form-control" placeholder="Password" required="" ng-model="user.password">
</div>
<div class="form-group">
<div class="checkbox i-checks"><label> <input type="checkbox"><i></i> Agree the terms and policy </label></div>
</div>
<button type="submit" class="btn btn-primary block full-width m-b">Register</button>
<p class="text-muted text-center"><small>Already have an account?</small></p>
<a ui-sref="login" class="btn btn-sm btn-white btn-block">Login</a>
</form>
出于某种原因,当我单击提交按钮时,没有任何反应。按钮已经死了。我的控制器有以下代码:
.controller('registerCtrl', ['$scope', '$state', 'Registration',
function($state, $scope, Registration) {
$scope.user = {
name: '',
email: '',
company: '',
password: ''
};
console.log('controller getting loaded');
$scope.signup = function(user) {
console.log('register getting called');
}
}]);
就好像表单无法识别“注册”方法一样。以类似的方式,我实现了一个登录表单:
<form class="m-t" ng-submit="login(credentials)" novalidate>
<div class="form-group">
<input type="email" class="form-control" placeholder="Email" required="" ng-model="credentials.email">
</div>
<div class="form-group">
<input type="password" class="form-control" placeholder="Password" required="" ng-model="credentials.password">
</div>
<button type="submit" class="btn btn-primary block full-width m-b">Login</button>
<a ui-sref="forgot_password"><small>Forgot password?</small></a>
<p class="text-muted text-center"><small>Do not have an account?</small></p>
<a class="btn btn-sm btn-white btn-block" ui-sref="register">Create an account</a>
</form>
和:
.controller('loginCtrl', ['$scope', '$rootScope', '$state', 'Authentication', 'AUTH_EVENTS',
function($scope, $rootScope, $state, Authentication, AUTH_EVENTS) {
$scope.credentials = {
email: '',
password: ''
};
$scope.login = function(credentials) {
Authentication.login(credentials).then(function(user) {
$rootScope.$broadcast(AUTH_EVENTS.loginSuccess);
$scope.setCurrentUser(user);
$state.go('events');
}, function () {
$rootScope.$broadcast(AUTH_EVENTS.loginFailed);
});
}
}]);
第二种形式正在按预期工作......我不知道发生了什么。我想说我记录了registerCtrl并且它被正确加载到页面中,但是该方法在调用时没有做任何事情。
对还有什么可能导致这种情况的任何想法?我已经在 SO 上检查了所有解决方案,但似乎没有任何帮助。
在我的 config.js 中,两条路由的声明方式类似:
.state('login', {
url: "/login",
templateUrl: "views/login.html",
data: { pageTitle: 'Login', specialClass: 'gray-bg' }
})
.state('register', {
url: "/register",
templateUrl: "views/register.html",
data: { pageTitle: 'Register', specialClass: 'gray-bg' }
})
我还尝试更改我的表单以在调用相同方法的“注册”按钮上单击 ng-click,但这具有相同的行为。
谢谢!