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 foll
It's a promise so it sets $scope.task after it returns. Until that return occurs $scope.task is undefined, which is what your second console.log is showing . At some later time the promise is resolved (completes) and $scope.task has a value, which is what your first console.log shows.