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から

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 に答える