1

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;
    }]);
maria salahuddin
  • 125
  • 2
  • 3
  • 16
  • An internal server error happens on the server. You provided code from the client. This won't help us a lot. – Deblaton Jean-Philippe May 02 '17 at 08:20
  • @DeblatonJean-Philippe check my edited question please – maria salahuddin May 02 '17 at 08:30
  • As it was said, this has nothing to do with Angular or client side JS. See what request is being sent in dev tools and fix it with server accordingly. Regarding the precedence of console.log, see http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call . – Estus Flask May 02 '17 at 12:26

0 Answers0