I am trying to understand the concept of factory and service in Angular. I have the following code under the controller
init();
function init(){
The first answer is great but maybe you can understand this:
studentApp.factory('studentSessionFactory', function($http){
var factory = {};
factory.getSessions = function(){
return $http.post('/services', {type :'getSource',ID :'TP001'});
};
return factory;
});
Then:
studentApp.controller('studentMenu',function($scope, studentSessionFactory){
$scope.variableName = [];
init();
function init(){
studentSessionFactory.getSessions().success(function(data, status){
$scope.variableName = data;
});
console.log($scope.variableName);
};
});