Reputation: 607
I am calling the class based view
class CurrentUser(APIView):
authentication_classes = (authentication.TokenAuthentication,)
def get(self, request, format=None):
for user in User.objects.all()
if request.user.is_authenticated():
fullname = user.get_full_name()
return Response(fullname)
from the url
url(r'^currentuser$', views.CurrentUser.as_view(), name='current-user'
I am getting current username. But I want to take that data into $scope of angularjs controller in following way.. Please.. Any help would be appreciated..
controllersModule.controller('homeCtrl', function($scope, $http, User , Product ,Process ,Ingredient) {
$scope.$on('event:login-confirmed', function() {
$scope.users = User.query();
$scope.products = Product.query();
$scope.processes = Process.query();
$scope.ingredients = Ingredient.query();
// $scope.currentUser = get;
});
});
Upvotes: 1
Views: 137
Reputation: 12019
I assume the User
is a service? If you are using the $http or Restangular you probably get a promise back. So you will end up with a promise in the scope, which is probably not what you want.
So you probably want this:
$scope.$on('event:login-confirmed', function() {
User.query().then(function(data) { $scope.users = data;});
...
});
Upvotes: 1