Abitar
Abitar

Reputation: 61

AngularJS -- Resources and using them before the fulfilled

I am having a big issue with Resources.

I created a mod to hold the resource, I have to use the same data in many different locations almost at the same time. one bigest is to populate a select list.

I can populate the select list with no problems, but the default selection is always blank.

I tried to use

 $scope.ServersList = Resource.List();
 $scope.Server = $scope.ServersList[1];

I tried to add a watch and it never went off when the promise was fulfilled;

This will populate the list but will not set the default. Im looking for solutions to the problem of the promise not being fulfilled tell after Server is set.

Upvotes: 1

Views: 44

Answers (2)

kfis
kfis

Reputation: 4729

Maybe like this

Resource.List().then(function(server){
  $scope.ServersList = server;
  $scope.Server = server[1]
});

regards

Upvotes: 1

Rob
Rob

Reputation: 2706

It hard to say whats going on with the information provided, but if this is happening inside a async call then make sure you are using apply.

$scope.$apply(function () {
  $scope.ServersList = Resource.List();
  $scope.Server = $scope.ServersList[1];
});

Upvotes: 0

Related Questions