I'm doing the CA course for angular. Here is the code for the controller, in controller.js:
app.controller('MainController', ['$scope', 'forecast', function($scope, forecast) {
forecast.success(function(data) {
$scope.fiveDay = data;
});
}]);
Here is the code for the service, in service.js:
app.factory('forecast', ['$http', function($http) {
return $http.get('http://s3.amazonaws.com/codecademy-content/courses/ltp4/forecast-api/forecast.json')
.success(function(data) {
return data;
})
.error(function(err) {
return err;
});
}]);
So I guess factories are services? What exactly is a service? I saw this explanation but it isn't the most clear to me.
Services
Syntax: module.service( 'serviceName', function ); Result: When declaring serviceName as an injectable argument you will be provided with an instance of the function. In other words new FunctionYouPassedToService().
In the two code snippets, when is the service called? What is the forecast.service doing in the controller? What is forecast = in the controller? Is it an object?