1

我正在调用基于类的视图

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)

从网址

url(r'^currentuser$', views.CurrentUser.as_view(), name='current-user'

我正在获取当前用户名。但我想通过以下方式将这些数据带入 angularjs 控制器的 $scope 中。请..任何帮助将不胜感激..

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

});
4

1 回答 1

1

我假设这User是一项服务?如果您使用的是 $http 或 Restangular,您可能会得到一个承诺。所以你最终会在范围内得到一个承诺,这可能不是你想要的。

所以你可能想要这个:

$scope.$on('event:login-confirmed', function() {
            User.query().then(function(data) { $scope.users = data;});
            ...
        });
于 2013-11-15T08:00:56.867 回答