I am trying to get data assigned to a $scope variable. Inside my $promise.then() function it is displaying correctly but outside the function it shows as undefined. The following is my controller code:
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);
});
The results inside the then() function:
[Object, Object, Object, Object]
The results outside the then() function:
undefined
The 'Tests' service factory I am using is the following:
angular.module('testSiteApp').factory('Tests', function($resource) {
return $resource('/api/test/:id', {id: '@id'}, { 'update': { method: 'PUT' } } );
});
Even when I use the query method instead of the get for my resource and set isArray to true I still end up with the same issue. For some reason the data is not binding to my scope inside the then function.
I am sorry if this is a repeat question but i looked everywhere and only found undefined issue relating to the $promise function which is no the issue in this case.
Thanks in advance for the support.