1

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;
        });

});

1 Answer 1

1

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

Comments

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.