find my below code for delete function its deleting in backend and returning success message to service from that not returning to controller ,so was unable to print growl message.
This is my controller side code:
$scope.deleteBlogswithid = function(id) {
var loggedInUserId = $rootScope.loggedInUser.id;
if ($rootScope.loggedInUser != null) {
blogService.deleteBlog(id, loggedInUserId,function(data) {
if(data == 'success'){
$location.path("/home");
$growl.box('Blog has been deleted', {
class : 'danger',
sticky : false,
timeout : 5000
}).open();
}
})
} else {
$growl.box('Please login to delete the blog', {
class : 'danger',
sticky : false,
timeout : 5000
}).open();
}
}
service.js:
blogbeatsApp.service('blogService', function(httpService) {
this.deleteBlog = function(id,loggedInUserId,data, callback) {
var url = 'blog/delete/' +id + "/" + loggedInUserId;
httpService.postRequest(url,data, callback);
};
});
httpService.js:this is my httpservice
blogbeatsApp.service('httpService', function($http, $location, $rootScope){
this.postRequest = function(url, data, contentType, callback){
$http({
method : 'POST',
url : url,
data : data,
headers : {
'Content-Type' : contentType
}
}).success(function(data) {
callback(data);
}).error(function(data, status, headers, config) {
});
};
i am not getting success message to controller in function(data).please help
httpService.postRequest(url,data, callback);yourcallbackis 3rdparameter of postRequest. Which is bind withfunction(url, data, contentType, callback)-contentTypesince its your 3rd parameter. use this in your httpServicethis.postRequest = function(url, data,callback, contentType)callback must be 3rd parameter