Factory vs Service
angularjs factory vs service do the same thing, just a different way of instantiation
by bchapman26
HTML
<div ng-controller="HelloCtrl">
<p>{{result}}</p>
</div>
<div ng-controller="HttpCtrl">
<p>{{result}}</p>
</div>
<br />
JavaScript
//angular.js example for factory vs service
var app = angular.module('myApp', ['ngResource']);
app.factory('Route', function($resource) {
return $resource('http://bamboo.commontrack-track-web-api-stag.appspot.com/activity/:id', {}, {});
});
function HelloCtrl($scope, $resource) {
var Route = $resource('/echo/json', {}, {});
Route.save({
id: 143001
}, {
id: 143001
}, function(response, getResponseHeaders) {
console.log(response);
$scope.result = response.id;
}), function(error) {
$scope.result = "error";
};
}
function HttpCtrl($scope, $http) {
$scope.result = "test";
}