1
找到我的下面的代碼刪除函數它的後端刪除,並返回成功的消息服務,從不返回到控制器,所以無法打印咆哮消息。servicenot的回調數據返回給控制器angularjs
這是我的控制器端代碼:
$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:這是我的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) {
});
};
我沒有得到成功的消息到控制器在功能(數據)。請幫助
您不以正確的順序傳遞參數。 'httpService.postRequest(url,data,callback);''callback'是postRequest的第三個'參數'。從第三個參數開始,它與'function(url,data,contentType,callback)' - 'contentType'綁定。在你的httpService中使用this.postRequest = function(url,data,callback,contentType)**回調必須是第三個參數** –
yes..now works.thank u – Jayashree
很高興幫助:)。 –