mgonto / restangular

AngularJS service to handle Rest API Restful Resources properly and easily
MIT License
7.87k stars 840 forks source link

Results from uirouter's resolve and getList().then() are similar, but not the same. #1252

Open jondthompson opened 8 years ago

jondthompson commented 8 years ago

The following two code snippets should result in the same data, but one is loaded prior to the state change and the other is loaded asynchronously. They're not. ng-repeat works with both of them, but I switched to angular-utils-pagination, and the latter code works, but the former code does not.

However, I don't see a difference in the arrays that are being generated, and they work with ng-repeat. I'm going to crosspost this issue to angular-utils-pagination and ui-router as well, as it's not handling the difference properly, as I'm not certain whether uirouter or restangular is in error for giving the wrong information in the first place.

doesn't work with angular-utils-pagination

.state( 'users', {
    url:'/users',
    controller: 'UsersCtrl',
    templateUrl: 'users/Users.tpl.html',
    data:{ pageTitle: 'Users' },
    authenticate: true,
    resolve: {
      users: ['Users', function(Users){
        return Users.getList({embed:'roles,user_certifications'});
      }]
    }
  })
.controller( 'UsersCtrl', function UsersController( $scope, users ) {
  $scope.users = users;
})
.factory('Users', function(Restangular){
  return Restangular.service('users');
})
;

works with angular-utils-pagination

.state( 'users', {
    url:'/users',
    controller: 'UsersCtrl',
    templateUrl: 'users/Users.tpl.html',
    data:{ pageTitle: 'Users' },
    authenticate: true
  })
.controller( 'UsersCtrl', function UsersController( $scope, Users ) {
  Users.getList().then(function(result){
   $scope.users = result;
   });
})
.factory('Users', function(Restangular){
  return Restangular.service('users');
})
;
jondthompson commented 8 years ago

Here's the other two issues I created for this issue. https://github.com/angular-ui/ui-router/issues/2308#issuecomment-147878147 https://github.com/michaelbromley/angularUtils/issues/246