I have created a service to communicate with a server via $http.post.
app.factory("dataService", [
"$http", "$q", "$timeout", function ($http, $q) {
function post(url, data) {
var deferred = $q.defer();
$http.post(url, data)
.success(function (result) {
deferred.resolve(result);
})
.error(function (error) {
deferred.reject(error);
});
return deferred.promise;
}
return {
post: post
};
In the controller I am doing:
dataService.get(someUrl,someData).
then(function (data) {
$scope.result = data;
});
Everything works fine, but if I call this generic "dataService" in some other service, for an example:
app.factory("userService", ["$http", "$q","dataService", function ($http, $q,dataService) {
function postUser(user) {
dataService.post(usersUrl, user);
}
return {
postUser: postUser
};
}
and call this "userService" in controller
userService.postUser($scope.user).then(){}
, I am getting the following error:
Can anyone explain me why this is happening?