I am having following example that shows the result achieved from a factory & a service. As per my knowledge, Factory always returns an object, while service always returns an instance of an object. Here, what is the difference in the 2 returned objects conceptually. Can someone clarify? (Particular to this scenario)
Snippet:
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js"></script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
<script>
//module declaration
var app = angular.module('myApp',[]);
//controller declaration
app.controller('myCtrl', function($scope, myFactory, myService){
$scope.name = "Peter";
var a = myService;
console.log(a);
var b = myFactory;
console.log(b);
});
//services declaration
app.service('myService',function(){
this.age = 15;
});
app.factory('myFactory',function(){
var obj = {};
obj.country = "USA";
return obj;
});
</script>
</body>
</html>
Result:
Already Read: