Attempting to incorporate a controller callback function within my service, triggering upon the success of an $http post request. The code snippet below provides a more detailed description.
Controller :
function UserAccountCtrl (UserService, $rootScope, listUsers) {
$rootScope.title = 'Comptes utilisateurs';
this.users = listUsers.data;
this.isShown = false;
this.isModification = false;
this.deleteEntry = function(entry){
this.users.splice(this.users.indexOf(entry), 1);
UserService.delete(entry);
};
this.show = function(){
this.isShown = true;
};
this.hide = function(){
this.isShown = false;
};
this.save = function(){
var success = function(data){
this.users.push(data);
};
var err = function(data){
alert(data);
};
UserService.post(this.user, success, err);
this.hide();
};
}
Service Function :
UserService.post = function (data,succ,err) {
$http({
url: __ADRS_SRV__ + "user",
method: "POST",
data:data,
isArray: true
}).success(function(data){
succ(data);
}).error(function(error){
err(error);
});
}
The process is straightforward: after posting a new user, the WebService adds it to mongo and sends back the newly created object. Retrieving the new object through console.log or an alert works perfectly fine.
However, I'm encountering an issue when attempting to push the new item into my array. An error message pops up stating:
Uncaught TypeError: undefined is not a function
This error occurs exactly where I try to push the new item into the array.
If anyone has any insights or suggestions, they would be greatly appreciated.
Thank you in advance