iam searching for a way to transfer the requested data from my service to the controller. a simple return data dont work....i wondering why?
test.factory(\'DataS
You can use $q and promise. $http
is an asynchronous call
factory
test.factory('DataService', function($http, $log, $q) {
return {
getEmployees: function( ) {
var d = $q.defer();
$http({method: 'GET', url: 'php/data.php'})
.success(function(data, status, header, config){
d.resolve(data);
}.error(function(error){
d.reject(error);
});
return d.promise;
},
getTest: function( ) {
return "test123";
}
};
});
Controller
DataService.getEmployees().then(function(data){
$scope.test = data;
});