var myModule = angular.module('motoAdsApp', []);
myModule.factory("AirportService", function ($http, $q) {
return {
getData : function(dateFrom, dateTo){
var deferred = $q.defer();
var response = $http({
method: "get",
crossDomain: true,
dataType:"xml",
contentType: "application/xml",
});
response.success(function (data) {
deferred.resolve(data);
});
response.error(function (data) {
alert('Error');
});
// Return the promise to the controller
return deferred.promise;
}
}
});
var motoAdsApp = angular.module("motoAdsApp");
motoAdsApp.controller('AirportControllers', function($scope, $http, AirportService) {
var result = AirportService.getData('09/07/2014', '09/14/2014').then(function(data) {
var json = $.xml2json(data);
$scope.airports = json.testData;
});
.......
The server gets hit twice when I load the page. Any idea why?