JGuizard
3/31/2016 - 9:56 AM

Data as JSON from Server or REST API

Data as JSON from Server or REST API

//FactoryService.js
app.factory('forecast', ['$http', function($http) { 
  return $http.get('https://s3.amazonaws.com/codecademy-content/courses/ltp4/forecast-api/forecast.json') 
            .success(function(data) { 
              return data; 
            }) 
            .error(function(err) { 
              return err; 
            }); 
}]);

//MainController.js
app.controller('MainController', ['$scope', 'forecast', function($scope, forecast) { 
    forecast.success(function(data) { 
    $scope.fiveDay = data; 
  });
}]);