Is it possible to load "async json" to $scope?

I want load json-data into my $scope.var . If i do this in my .Controller

$http.get(‘http://…/app.php’).success(function(data) { $scope.var= data; });

it works fine.

But if i do this with .Factory + .Controller i get a problem.

factory:

.factory(‘daten’, function($http) {
return {
all: function() {
$http.get(“http://…/app.php”).then(function(data){
return data;
});
}, …

.controller

$scope.var = daten.all();
// DEBUG: $scope.var is “undefined”

I think I know the problem ( $scope.var is undefined, because i get Json-data later), but i have no solution for this.

I try $scope.$apply(… and also daten.all().then(… but get an error.

You need $q and promisses in order to achieve this. You can read about it here https://docs.angularjs.org/api/ng/service/$q