1

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 Answer 1

3

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);
    });
}]);
Sign up to request clarification or add additional context in comments.

4 Comments

If the console.log outputs the correct info you are setting the value somewhere else.
Try inserting a {{ workplaces }} tag in your HTML (inside the controller) and see if it renders anything.
Thanks for replies. I found a problem. I've made a typo in ng-repeat that i use to render data in view.
I was going to ask for your view code... why people post half the relevant stuff these days... 😊

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.