0

i have a probleme with angularJs and java, when i send an object from service(AngularJs) it will be incomplete in java part

angularjs code:

$scope.nouveauAcompte= function() {
           var result=[];
           angular.forEach($scope.cras, function (row) {
               console.log(row);
               row.acompte.acoTotalMontant +=row.acompte.acoMontant;
               row.acompte.typeAcompte.atyId=row.acompte.typeAcompte.atyId;
               row.acompte.cras.Id=row.id;
               row.acompte.acoDate=new Date();

               var formatted_date = row.acompte.acoDate.getDate() + "/" + (row.acompte.acoDate.getMonth() + 1) + "/" + row.acompte.acoDate.getFullYear()
               row.acompte.acoDate=formatted_date;
              result.push(row.acompte);


           })
           $scope.acomptes=result;

            AcompteService.nouveauAcompte(
                    $scope.acomptes).success(function(data) {

            }, function(error) {

            });

        };

service.js

            nouveauAcompte: function (acomptes) {
                var parameter = JSON.stringify(acomptes);
                      return $http.post('addAcompte', parameter)
                      .success(function (data, status, headers) {
                     })
                     .error(function (data, status, headers) {

                     });
           },

javascript part

java part

as you can see the object is incomplete and i dont know why .

georgeawg
  • 48,608
  • 13
  • 72
  • 95
junior
  • 1
  • 5
  • The `.success` method has been [removed from the AngularJS framework](https://stackoverflow.com/questions/35329384/why-are-angularjs-http-success-error-methods-deprecated-removed-from-v1-6/35331339#35331339). – georgeawg Oct 09 '19 at 13:45
  • ok but that work correctly and it's not the problem – junior Oct 09 '19 at 14:09

1 Answers1

0

I suggest you to change the code like this:

nouveauAcompte: (acomptes) => {
    var parameter = JSON.stringify(acomptes);
    return $http.post('addAcompte', parameter)
            .then(response => {
                // response.data
                // response.status
                // response.headers
            })
            .catch(error => {
                // Do the logic if the request is broken
            });
}

This piece of code is not good:

AcompteService.nouveauAcompte($scope.acomptes).success(function(data) {

}, function(error) {});

Transform it into:

AcompteService.nouveauAcompte($scope.acomptes).success((data) => {
    // Do something
}).error((error) => { // Do something});
Simone Boccato
  • 199
  • 1
  • 14