Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

I am currently working on angular app and bumped into a problem. The problem is when I'm getting the data form backend through factory into controller, eventhrough I apply this data to scope I can't access it later in this controller.

My fist try:

Schema.list.get().$promise.then(function (data) {
    $scope.schema= data;
});

With this method I can print data in my view but if I when I want to access it in controller scope is undefined.

Second try:

Schema.list.get().$promise.then(function (data) {
    $scope.$apply(function() {
        $scope.schema= data;
    });
});

When I use $scope.$apply I got an error like this:

Error: [$rootScope:inprog] $digest already in progress
http://errors.angularjs.org/1.4.6/$rootScope/inprog?p0=%24digest
    at angular.js:68
    at beginPhase (angular.js:16279)
    at Scope.$apply (angular.js:16020)
    at racunanje.client.controller.js:11
    at processQueue (angular.js:14678)
    at angular.js:14694
    at Scope.$eval (angular.js:15922)
    at Scope.$digest (angular.js:15733)
    at Scope.$apply (angular.js:16030)
    at done (angular.js:10545)

Thank you in advance for any help you can give me.

share|improve this question
    
Could you describe how you try to access your data later in your controller? My guess is that you try in a synchronous way. – Adlen Afane Oct 24 at 16:30
    
try defining $scope.schema in your controller when it's initialized and then update that value with the return of the promise – user2954587 Oct 24 at 16:30
    
$scope.schema also if I console.log($scope.schema) result is undefined – Miha2255 Oct 24 at 16:31
    
@user2954587 value is the same as predifined, it's not updated. – Miha2255 Oct 24 at 16:34
1  
what does can't access it later mean? Provide more code and explanation of what you are trying to do – charlietfl Oct 24 at 16:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.