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(‘daten’, function($http) {
return {
all: function() {
return data;
}, …


$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$q