Accessing $scope in AngularJS factory?

You don’t typically use $scope inside a factory, service or provider. Usually, you would return the promise (returned by $http) and then handle the promise in a controller (where you do have $scope).

factory.edit = function(id){
    return $http.get('?controller=store&action=getDetail&id=' + id);
}

Controller function:

$scope.edit = function(id) {

    deleteFac.edit(id).then(function(response) {
        $scope.something = response.model;
    });
}

Leave a Comment