Sorry friends,I put wrong code and correcting here. I am trying to $scope in my Angular service but as obvious giving error-
ReferenceError: $scope is not defined
Here is my code in service-
app.factory('fetchEmpService', function ( $scope,$http) {
var editEmp = function (EID) {
debugger;
for (i in $scope.employees) {
if ($scope.employees[i].EmpId == EID) {
$scope.newemployee = {
EmpId: $scope.employees[i].EmpId,
Name: $scope.employees[i].Name,
Age: $scope.employees[i].Age,
City: $scope.employees[i].City,
Gender: $scope.employees[i].Gender
};
}
}
}
return {
editEmp:editEmp
}
}
And in my controller I am trying to consume service like this-
$scope.EditEmployee = function (EID) {
debugger;
$scope.employees = fetchEmpService.editEmp(EID);
}
I googled about it and found that we can not inject like this. But not found any appropriate solution.