Trying to return JSON data is causing a error in my service. Here is the code...looks simple enough!
var app = angular.module('easyjet', []);
app.service('FlightsService', function($http) {
return {
'selectedResult': null,
'resultsData': $http.get('http://ejtestbed.herokuapp.com/flights')
};
});
app.controller('ResultsController', function($scope, FlightsService) {
// Default sort setting
$scope.order = "flightNumber.number";
// Using service
$scope.flights = FlightsService;
});
app.controller('DetailedFlightController', function($scope, FlightsService) {
// Using service
$scope.flights = FlightsService;
});
How can I fix this? Thanks in advance
$http.getwill return a$promise. Basically saying i will return something at some point. You have 2 callback possibilities 1.success 2.error.$promise.then(function(data){//success;},function(){//err;}). As for the usage @Rob provided a really good fiddle for your case, namelyFlightsService.resultsData().then(function(response) {//do smth wih your data});