Reputation: 1013
I am trying to write a post request to log in a user and nothing works. I can't see why and would be happy about any help! Thanks!!
My controller:
'use strict';
app.controller('loginController', function($scope, $state, $http){
$scope.submitLogin=function(email,password)
return $http.post('/login', {email:$scope.email, password:$scope.password })
//since i have ng-model="email"- I don't actually need to pass in $scope.email but can pass in only email ?!
.then(function(success){
if (sucess){
console.log(success)
$state.go('stories')
}
else {
console.log('error')
}
})
.catch(function(err){
console.log("bad")
})
})
Part of the HTML:
<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>
State:
'use strict';
app.config(function ($stateProvider) {
$stateProvider.state('login', {
url: '/login',
controller:'loginController',
templateUrl: '/browser/app/login/login.html'
});
});
Upvotes: 0
Views: 36
Reputation: 275
Put ng-model in input tag.
$scope.submitlogin=function(){
data={
email:$scope.email,
password:$scope.password
}
$http.post('/login',data).success(function(){
});
}
try in this way.It might work.
Upvotes: 1