我正在尝试编写登录用户的帖子请求,但没有任何作用。我不明白为什么,并会为任何帮助感到高兴!谢谢!!Angular - 无法发送POST请求登录用户,不知道什么是错的?
我的控制器:
'use strict';
app.controller('loginController', function($scope, $state, $http){
$scope.submitLogin=function(email,password)
return $http.post('/login', {email:$scope.email, password:$scope.password })
//因为我有NG-模型=“电子邮件” - 我实际上并不需要在$ scope.email通过,但只能用电子邮件传递?!在HTML的
.then(function(success){
if (sucess){
console.log(success)
$state.go('stories')
}
else {
console.log('error')
}
})
.catch(function(err){
console.log("bad")
})
})
部分:
<div class="form-group">
<label ng-model="email">email</label>
<input type="text" class="form-control" required />
</div>
<div class="form-group">
<label ng-model="password">password</label>
<input type="password" class="form-control" required />
</div>
<button type="submit" class="btn btn-block btn-primary" ng-click="submitLogin()">login</button>
</form>
国家:
'use strict';
app.config(function ($stateProvider) {
$stateProvider.state('login', {
url: '/login',
controller:'loginController',
templateUrl: '/browser/app/login/login.html'
});
});
您需要将ng-model =“email”放入您的输入中而不是标签中。 –
让我知道当你把ng模型输入到输入时它是否仍然不起作用。 –
谢谢。它仍然无法正常工作,我得到这个奇怪的错误:错误:[ng:areq] http://errors.angularjs.org/1.3.20/ng/areq?p0=loginController&p1=not%20aNaNunction%2C%20got% 20定义 – javascript2016