return JS method

Asked

Viewed 48 times

1

I have the following method:

 $scope.upload = function (files) {
    if (files && files.length) {
        for (var i = 0; i < files.length; i++) {
            var file = files[i];
            if (!file.$error) {
                Upload.upload({
                    url: '/CreCpa/getExtrato',
                    data: {
                       // tela: "tarefa",
                       //registro: $scope.registro2.t0060_id_tarefa,
                        file: file
                    }
                }).then(function (resp) {
                    //$timeout(function () {
                    //    $scope.log = 'arquivo: ' +
                    //    resp.config.data.file.name +
                    //    ', resultado: ' + JSON.stringify(resp.data) +
                    //    '\n' + $scope.log;
                    //});
                }, null, function (evt) {
                    //var progressPercentage = parseInt(100.0 *
                    //        evt.loaded / evt.total);
                    //$scope.log = 'progress: ' + progressPercentage +
                    //    '% ' + evt.config.data.file.name + '\n' +
                    //  $scope.log;                      
                })
            }
        }
    }
};

this method works normally, and returns a json, my doubt is how to take the data of the json and put in a variable, since q do not know in which "variable" is being returned that json.

I tried to put a . Success;

$scope.upload = function (files) {
    if (files && files.length) {
        for (var i = 0; i < files.length; i++) {
            var file = files[i];
            if (!file.$error) {
                Upload.upload({
                    url: '/CreCpa/getExtrato',
                    data: {
                       // tela: "tarefa",
                       //registro: $scope.registro2.t0060_id_tarefa,
                        file: file
                    }
                }).then(function (resp) {
                    //$timeout(function () {
                    //    $scope.log = 'arquivo: ' +
                    //    resp.config.data.file.name +
                    //    ', resultado: ' + JSON.stringify(resp.data) +
                    //    '\n' + $scope.log;
                    //});
                }, null, function (evt) {
                    //var progressPercentage = parseInt(100.0 *
                    //        evt.loaded / evt.total);
                    //$scope.log = 'progress: ' + progressPercentage +
                    //    '% ' + evt.config.data.file.name + '\n' +
                    //  $scope.log;                      
                }).success(function (data) {
                     $scope.transactions = data;

                });
            }
        }
    }
};

but made that mistake: inserir a descrição da imagem aqui

this is the return: inserir a descrição da imagem aqui

  • Dude, put it on . then right...

  • Upload is a variable that references angular http? The error message is very clear, there is no method then..success.

  • Solved your doubt?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.