1

I have this defined in controller $scope.files = {};

Then I have a ajax call to get data and pass to $scope.files;

In the same controller. I have a ng-click function which I want to manipulate $scope.files How to do that because it is async. I tried and the $scope.files always return blank {}

$scope.click = function() {
 //Do something to $scope.files;
}
4
  • 1
    You're not really showing us enough code to help you. Do you have a fiddle or a plunker you can show? Commented Mar 3, 2014 at 16:42
  • Are you calling $scope.click() in the callback of your get request? Commented Mar 3, 2014 at 16:53
  • @blesh ok, I will make a plunk later. Its late here. Commented Mar 3, 2014 at 17:00
  • @ZackArgyle I call it outside and inside the cb both not work. Commented Mar 3, 2014 at 17:00

2 Answers 2

2

My fault. this is not related to async. I can actually get the data.

My problem is the return data is object and I tried to use .length to get the length of object so it always return 0 and {}. And I found .length for array.

and Object.keys(a) for object sizes

Sign up to request clarification or add additional context in comments.

Comments

1

Looks like you need to use promise/deferred implementation. Promises allow you to execute code and once the promise is returned then continue.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.