I want to implement the login method with AngularJS, Node and MongoDB. I have built a Restful API where I send the request.
When I try to execute the GET request this error appears at the console TypeError: UserService.logIn(...).success is not a function
Succeess doesnt exist like the $http
way?
I also found this but I cannot understand how to adjust it to fit my code.
HTTP GET "class" actions: Resource.action([parameters], [success], [error])
non-GET "class" actions: Resource.action([parameters], postData, [success], [error])
non-GET instance actions: instance.$action([parameters], [success], [error])
Service.js
var appServices = angular.module('starter.services', ['ngResource']);
appServices.factory('UserService', function ($resource) {
return {
logIn: function (email, password) {
return $resource("http://localhost:3000/users/login", {
email: email,
password: password
});
}
}
});
Controller.js
var apps = angular.module('starter.controller', []);
apps.controller('loginCtrl', function ($scope, $ionicPopup, $state, UserService) {
$scope.doLogin = function doLogin(email, password) {
if (email != null && password != null) {
UserService.logIn(email, password).success(function (data) {
$state.go('tabs.home');
}).error(function (status, data) {
var ionicPop = $ionicPopup.alert({
title: 'Login Failed',
template: 'Invalid email or password.\nPlease try again!'
});
console.log(status);
console.log(data);
});
}
};
});