var Presentation = Presentation || {}; Presentation.Sh = Presentation.Sh || {}; Presentation.Sh.Serverhousing = function($scope, $http, $q){ //all convert to string of price because of unsafe angular binding need string $scope.totalPrice = ''+serverDef.basePrice; var lastSendedConfig = ''; $scope.$on('SH_CONFIG_EMERGED', function(event, shConfig){ lastSendedConfig = shConfig; $scope.totalPrice = ''; // post here because of limitation of get params $http({ url: '/api/prices/serverhousing.php', method: "POST", // data: $.param({ configuration : shConfig }), data: 'configuration='+encodeURIComponent(shConfig), headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, }) .success(function(data, status, headers, config){ if(lastSendedConfig != data.sendedConfiguration){ return; } $scope.totalPrice = ''+data.price; }) ; }); };