I want to change my service `myFct` but I have a problem:

> 
> This is my current service which works well
> 
> 
> 

Factory

```
angular.module('MyApp')
.factory('myFct', myFct);

function myFct(){
    return{
        getMyData : function() {
            return $http.get('./my/data.json');
        }
    }
}

```

Controller

```
app.module('MyApp')
.controller('myCtrl', myCtrl);

myCtrl.$inject = ['myFct'];

function myCtrl(myFct){
    vm = this;
    vm.myData = myData();

    function myData(){
        myFct.getMyData().success(function(data){
            vm.myData = data;
        });
    }
}

```

> 
> I want to manage the $http success in my factory, for example
> 
> 
> 

Factory

```
angular.module('MyApp')
.factory('myFct', myFct);

function myFct(){
    return{
        getMyData : function() {
            return $http.get('./my/data.json').success(function(data){
                return data;
            });
        }
    }
}

```

Controller

```
app.module('MyApp')
.controller('myCtrl', myCtrl);

myCtrl.$inject = ['myFct'];

function myCtrl(myFct){
    vm = this;
    vm.myData = myFct.getMyData();
}

```

The result of variable `vm.myData` is undefined. I am aware that the service $http is asynchronous, but how can I handle it in such a way that the variable `vm.myData` is equal to the data of the my json file?