Service:
var myModule = angular.module('myApp', []);

myModule.factory("AirportService", function ($http, $q) {

    return {
        getData : function(){
            var deferred = $q.defer();
            var response = $http.get("griddata.json");
            response.success(function (data) {
                deferred.resolve(data);
            });
            response.error(function (data) {
                alert('Error 123');
            });
            // Return the promise to the controller
            return deferred.promise;
        }
    }
});

Controller:
var myModule = angular.module("myApp", []);
myModule.controller('AirportControllers', [function ($scope, $http, 
AirportService) {
    AirportService.getData().then(function(data) {
        $scope.agents = data;
    });    
}]);

No matter what I do I get:
TypeError: Unable to get property 'getData' of undefined or null reference
 at Anonymous function (http://..../angular/controllers.js:3:5)

Any idea?

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to