I am writing a program to connect to a rest api... But factory function doesnt work ... While everything seems to be correct
factory:
app.factory('publisherService', ['$http', function($http){
var services = {};
var userInfo = {};
services.getUser = function()
{
$http({method: 'GET', url: '/phoenix/publisher/user'}).success(function(data){
userInfo = data;
});
return userInfo;
};
return services;
}]);
controller:
app.controller('publisher', ['$scope','publisherService', '$http',function($scope, publisherService,$http)
{
$scope.publisher = {};
$scope.publisher = publisherService.getUser();
}]);
When program runs $scope.publisher returns {}
But the following code runs well
app.controller('publisher', ['$scope','publisherService', '$http',function($scope, publisherService,$http)
{
$scope.publisher = {};
$http( {method: 'GET', url: '/phoenix/publisher/user'} ).success(function(data){
$scope.publisher = data;
});
}]);