I am trying to call a function inside AngularJS service. Below is code- EmployeeService.js:
/// <reference path="script.js" />
app.factory('fetchEmpService', function ($scope, $http) {
var fetchEmp= function()
{
var empList;
$http.get("EmpWebService.asmx/GetEmp")
.then(function (response) {
empList = response.data;
//return response.data;
//$scope.employees = response.data;
});
return empList;
}
return {
fetchEmp:fetchEmp,
};
});
My main script file where I am calling service is-
$scope.employees = fetchEmpService.fetchEmp();
It's not giving any error but no result is coming in it, seems it's returning blank. When I debugged by Browser Inspector I found that web service response is having data in Object form. So why it is not coming. Another question is, can we not inject $scope in AngularJS service factory?