How to add 2 variables within a JSON obtained from a Web services in angularjs?

1

I have a big question, today I am consuming data from a web services as always, using angularJS and I have a new problem:

I consume a web services that in response gives me the following:

{success: "true", n_sucursales: 2, id_sucursal: "19", id_servicio: "38,39",…}
activo_modulos:"1,1"
id_modulos:"18,52"
id_servicio:"38,39"
id_sucursal:"19"
n_modulos:2
n_sucursales: 2
nombre_modulos: "1 - Farmacia Preferencial,2 - Farmacia Preferencial"
nombre_servicio: "NORMAL,PREFERENCIAL"
nombre_sucursal:"Hospital Sótero"
success:"true"

If you realize there are variables that bring me two data, in this case I focus on ID_SERVICIO because I have to send that data to another web services.

How I send them: first I configure url, method, etc. in a service and then the data obtained I save it in a variable and finally I send it that way (I would like to make only one request):

//consume los datos de id_servicio 38 [NORMAL]
Conection.Colaservices({
        id_servicio: SaveCredentials.getData().id_servicio.split(',')[0]
    },
    function(response) {
        console.log('normal', JSON.stringify(response.data));
        $scope.normal = response.data;
    });

//consume los datos de id_servicio 39 [PREFERENCIAL]
Conection.Colaservices({
        id_servicio: SaveCredentials.getData().id_servicio.split(',')[1]
    },
    function(response) {
        console.log(JSON.stringify(response.data));
        $scope.preferencial = response.data;
    });

Resulting in:

//NORMAL : 38
{success: "true",…}
data:
    {id_servicio: "38", personas_esperando: "1", personas_atendidas: "706", tiempo_espera: "0",…}

id_servicio:"38"
id_ticket:"0"
letra:"-"
numero:"0"
personas_atendidas:"706"
personas_esperando:"1"
rut:"-"
tiempo_espera:"0"
success:"true"

//PREFERENCIAL: 39
{success: "true",…}
data:
    {id_servicio: "39", personas_esperando: "0", personas_atendidas: "208", tiempo_espera: "0",…}

id_servicio:"39"
id_ticket:"0"
letra:"-"
numero:"0"
personas_atendidas:"208"
personas_esperando:"0"
rut:"-"tiempo_espera:"0"
success:"true"

Question: How to add personas_atendidas : "706" of NORMAL with people_aids: "208" of PREFERENCIAL (ie show 914)?

    
asked by Hernan Humaña 01.10.2016 в 03:43
source

1 answer

1
//consume los datos de id_servicio 38 [NORMAL] 

Conection.Colaservices({

   id_servicio: SaveCredentials.getData().id_servicio.split(',')[0]},

   function(response){

        //console.log('normal',JSON.stringify(response.data));

        $scope.normal = parseInt(response.data.personas_atendidas);
   }

});

//consume los datos de id_servicio 39 [PREFERENCIAL]

Conection.Colaservices({

    id_servicio: SaveCredentials.getData().id_servicio.split(',')[1]},

    function(response){

          //console.log(JSON.stringify(response.data));

          $scope.preferencial = parseInt(response.data.personas_atendidas);
    }
});

...

//codigo

$scope.personas_atendidas = $scope.normal + $scope.preferencial;
    
answered by 01.10.2016 / 04:37
source