I am trying to get the data assigned to the $ scope variable. Inside my function $ prom.then (), it displays correctly, but outside the function it displays as undefined. Below is the code of my controller:
angular.module('testSiteApp').controller('TestController', function ($scope, Tests) { $scope.test = Tests.get({id: 1}); $scope.test.$promise.then(function(data) { $scope.tasks = data.tasks; console.log($scope.tasks); }); console.log($scope.tasks); });
Results inside the then () function:
[Object, Object, Object, Object]
Results outside the then () function:
undefined
Service "Tests" factory I use the following:
angular.module('testSiteApp').factory('Tests', function($resource) { return $resource('/api/test/:id', {id: '@id'}, { 'update': { method: 'PUT' } } ); });
Even when I use the request method instead of get for my resource and set isArray to true, I still get the same problem. For some reason, the data is not required for my area inside the then function.
I apologize if this is a recurring question, but I searched everywhere and found an undefined problem related to the function $ prom, which in this case is not a problem.
Thanks in advance for your support.