I have the following code in which First I get rating from user and then I want to fetch data of order
from OrderService.getOrder
method using OrderService and then pass rating and order to OrderService.ratingHero
method But it gives an error of 500
One more thing is When I debug the code the
console.log("rating"+ $scope.hero.rating);
is run before the OrderService.getOrder
Can anyone tell me why ?
RatingHeroCtrl.js
'use strict';
angular.module('Orders').controller('RatingHeroCtrl',['$scope','$state', '$ionicModal', 'MessageService', 'SettingService', 'OrderService','UserService',
function($scope, $state, $ionicModal, MessageService, SettingService,OrderService,UserService) {
$scope.heroName = "Danish";
(function initialize(){
$scope.hero = {};
$scope.rider = {
ratingsObject : {
iconOn: 'ion-ios-star', //Optional
iconOff: 'ion-ios-star-outline', //Optional
iconOnColor: 'rgb(200, 200, 100)', //Optional
iconOffColor: 'rgb(200, 100, 100)', //Optional
rating: 0, //Optional
minRating: 0, //Optional
// readOnly: ratingReadOnly, //Optional
callback: function(rating, index) { //Mandatory
$scope.ratingsCallback(rating,index);
}
}
}
})()
$scope.ratingsCallback = function(rating, index) {
$scope.hero.rating = rating;
OrderService.getOrder($state.params.orderId,
function(response) {
$scope.hero.order = response;
console.log("order"+$scope.hero.order);
},
function(error){
console.log("error");
}
)
console.log("rating"+ $scope.hero.rating);
console.log("order2"+$scope.hero.order);
// console.log("user"+$scope.hero.rater);
OrderService.ratingHero($scope.hero).then(function(response){
console.log(success);
}, function(error){
console.log(error);
})
};
}]);
OrderService.js
angular.module('Orders')
.service('OrderService', ['$http', '$state', '$resource', '$q', 'SettingService', '$localStorage', "MessageService",
function($http, $state, $resource, $q, SettingService, $localStorage, MessageService) {
var orderResource = $resource(SettingService.baseUrl + "api/orders/:id", {id:'@id'}, {'query':{method:'GET', isArray:false}, 'update':{method:'PATCH'}});
var service = {
ratingHero : function(hero){
return $http({
method: "POST",
url: SettingService.baseUrl + "api/heroRatings",
data: hero
});
},
getOrder : function(OrderId, successCallback, failureCallback){
orderResource.query({id:OrderId}, successCallback, failureCallback);
}
}
return service;
}]);