如何修复错误:TypeError:logger.logSuccess不是函数

时间:2019-07-17 11:49:00

标签: java angularjs spring

我正在使用Spring mvc开发后端服务,并且前端客户端在angularjs中。成功上传文件后,我试图向前端用户发送消息,但是上面的错误始终在我的控制台中弹出。我需要在代码中哪里更正:?

Java:

    @Override
    public CompasResponse UploadClaim(String filePath) {
        try
        {
            ArrayList<Claim>list = getClaimsExcel(filePath);
             if (uploadClaims(list))
             {

                return new CompasResponse(200, "Uploaded Successfully");
            } else {
                return new CompasResponse(201, "Oops! No Records to upload");
            }
        }
        catch(IOException e) { e.printStackTrace(); return new CompasResponse(201, "Error. Could not process uploaded document."); }

    }

Javascript:

uploadclaimApp.controller('uploadclaimCtrl', //['$scope', '$filter', 
'uploadclaimSvc','organizationSvc', '$rootScope', 
//'blockUI', 'logger', '$location','$http',
//function ($scope, $filter, uploadclaimSvc,organizationSvc, $rootScope, 
blockUI, logger, $location,$http) 
    ["$scope", "$filter", "uploadclaimSvc", "localStorageService",  
"$rootScope", "blockUI", "logger", "$location", function ($scope, $filter, 
uploadclaimSvc, $rootScope, blockUI, logger, $location, localStorageService)
        $scope.uploadClaim = function()
    {
        console.log('uploading: ', $scope.myFile);
        uploadclaimSvc.saveFile($scope.myFile, $scope.orgId).success(function(response){
            if (response.respCode == 200) {
                logger.logSuccess("Great! The service information was saved successfully.")
                } else  {
                    logger.logWarning(response.respMessage);
                }
        });
    }
}]);

uploadclaimApp.service('uploadclaimSvc', function($http){
    this.saveFile = function (file,orgId) {
            console.log("uploading file...");
            var fd = new FormData();
            fd.append('file', file);
            fd.append('orgId',orgId);
            return $http({
                url: '/compas/rest/transaction/uploadclaim',
                method: 'POST',
                transformRequest: angular.identity,
                headers: { 'Content-Type': undefined },
                data: fd
            });
        };
}); 

我希望文件上传成功/失败时会向用户显示一条消息

1 个答案:

答案 0 :(得分:0)

就像错误说一样。logger.logSuccess未定义。也许您可以使用ng-serviece $log代替。