9

So it looks like in the examples you can do this:

App.controller('ProjectListCtrl', ['$scope', 'Restangular', function($scope, Restangular) {
  $scope.projects = Restangular.all('project/').getList();
}]);

But that doesn't work for me. When I ng-repeat project in projects and look at the scope, I see:

{ 
projects:  { 
  then: null
  catch: null
  finally: null
  call: null
  get: null
  restangularCollection: true
  push: null
 } 
}

Which looks like an un resolved promise object right?

This works fine but is more verbose:

lgtApp.controller('ProjectListCtrl', ['$scope', 'Restangular', function($scope, Restangular) {
  Restangular.all('project/').getList().then(function(projects){            
    $scope.projects = projects;                                             
  });                                                                       
}]);                                                                        

Did I miss something? This is in the docs:

$scope.owners = house.getList('owners')

Shouldn't matter, but this happens when I'm testing a phonegap app in the Ripple chrome plugin.

3 Answers 3

12
$scope.projects = Restangular.all('project/').getList().$object;
1
  • In the current version (Restangular 1.5.1, Angular 1.3.15) this approach seems to work, as the actual array is within the property, $object.
    – methai
    Commented May 6, 2015 at 20:19
9

As an addition to the other comment, even though promise unwrapping was disabled, I implemented in Restangular a new way of having promises unwrap easily for you (Similar to what $resource does what without removing Promises). Check https://github.com/mgonto/restangular#using-values-directly-in-templates for more information :)

1
7

As of angular 1.2, automatic unwrapping of promises was disabled and deprecated. So, while

$scope.projects = Restangular.all('project/').getList();

would have allowed you to access projects in your view directly in previous releases (for which the Restangular docs where likely written), that will no longer work automatically. You can reenable the feature via the $parseProvider.unwrapPromises() API, but it is deprecated, so your best bet is probably to manually resolve the promise in your controller like in your more verbose example.

See the checkin commit message for more details.

Not the answer you're looking for? Browse other questions tagged or ask your own question.