1
votes

I'm receiving data from the resource factory, but when I try to output this it renders elements, but remains empty. It's strange because I can see it resolved in the console log.

Controller

dichotomy.controller('WorkplaceOverview', ['$scope', 'WorkPlace', function ($scope, WorkPlace) {
$scope.workplaces = WorkPlace.all({get_all:1}).$promise.then(function (response) {
        $scope.workplaces = response;
         console.log($scope.workplaces);
    });
}]);

Factory

    dichotomy.factory('WorkPlace', function ($resource) {
    return $resource('api/create_workplace/:id/:get_all/', {}, {
        all: {method: "GET", isArray: true, params: {get_all: '@get_all'}},
        get: {method: "GET", isArray: false, params: {id: '@id'}},
        update: {method: 'PUT', params: {id: '@id'}}
    });
});
1

1 Answers

3
votes

You're assigning the value twice (second time to a promise).

Try

dichotomy.controller('WorkplaceOverview', ['$scope', 'WorkPlace', function ($scope, WorkPlace) {
  WorkPlace.all({get_all:1}).$promise.then(function (response) {
      $scope.workplaces = response;
      console.log($scope.workplaces);
    });
}]);