I've got a function in an Angular controller like so:
app.controller("UsersController", ["$scope", "UserList", function($scope, UserList) {
$scope.createUserSubmit = function(newUser) {
UserList.createUser().success(function(data){
console.log(data);
});
}
}]);
When the createUserSubmit() function is called, it calls another function to a function createUser() in a service UserList.
The service looks like this:
app.service("UserList", function() {
this.createUser = function(){
console.log("doing it");
return "hi";
}
});
Now, when this all runs, I get the "doing it" message logged, but then I get the following error and the console.log(data) does not log.
TypeError: undefined is not a function
Normally this type of error would be self explanatory, so either I'm being a moron or there's something confusing going on. As far as I can see, it is a function.
.successdoes not become available automatically from any return value, you need to return angular httpPromise for thatcreateUser()function. I then return the data from that call. If I can't do.success, how can I do a callback with the returned data?