Go through a list with angularjs

0

I have an error saving a list in angularjs

when checking with is sending data when saving

        $scope.agregarTecnologiaSeleccionado = function (tecnologia) {

        $scope.solicitud.IdSolicitudTecnologia = tecnologia.Id;

        $scope.listaTecnologiaSeleccionada.push(tecnologia);

        $scope.solicitud.Tecnologia = [];

        for (var i = 0; i < $scope.listaTecnologiaSeleccionada.length; i++) {

            var tecnologia = [
                {
                      Id: $scope.listaTecnologiaSeleccionada[i].Id
                    , Nombre: $scope.listaTecnologiaSeleccionada[i].Nombre
                }
            ];

            $scope.solicitud.Tecnologia.push(tecnologia);
        }

        console.log($scope.solicitud.Tecnologia);
    }

I do not save since I see that it sends an arrangement inside another. How do I solve it?

thank you very much

    
asked by Camilo López 19.02.2018 в 18:46
source

1 answer

1

You can try this, it's easier

angular.forEach($scope.listaTecnologiaSeleccionada, function(value, key){
     var tecnologia = {
         Id : key,
         Nombre : value
     }
     $scope.solicitud.Tecnologia.push(tecnologia);
   });

However, the detail in your code is here:

var tecnologia = [
                {
               Id: $scope.listaTecnologiaSeleccionada[i].Id
                        , Nombre: $scope.listaTecnologiaSeleccionada[i].Nombre
                }
];

since you are first adding an Array, and within that array you are creating an Object, that is, Array = [] and Object = {}

Hopefully it works for you

    
answered by 19.02.2018 / 19:06
source