Vector gets values wrong way

Asked

Viewed 34 times

0

Hello, I’m using angular and pouchdb to insert value into an array. but currently with the code below when using the command console.log(vetorPrincipal); he returns like this screenshot, vetor retornando de forma errada

The right thing would be to return like this

Exibindo corretamente

My code and this one below.

 var vetorPrincipal = [];
 insereNoVetor();
  console.log(vetorPrincipal);      
 function insereNoVetor() {
   // verifica se variaveis estão preenchidas, se estiverem então Zera
   if(vetorPrincipal[0] != undefined) {
     vetorPrincipal = [];
     jk = [];
   };
   if($scope.relatorioX.LeituraRelatorio[0] == "todos"){
     $pouchDB.find("relatorio", $scope.relatorioX.IDRelatorio).then(function (resultado) {
       return resultado.docs
     }).then(function (vetor) {
        angular.forEach(vetor, function(vale, key){
          $pouchDB.findleiturasRelatorio(vale._id).then(function (valor) {
            angular.forEach(valor.docs, function (v,k) {
              vetorPrincipal.push(v);
            });
          });

        });

     });
   }else{
     angular.forEach($scope.relatorioX.LeituraRelatorio, function (v,k) {
       $pouchDB.findleiturasRelatorio(v).then(function (resultado) {
         angular.forEach(resultado.docs, function (o,p) {
           vetorPrincipal.push(o);
         });
       });
     });
   }
 }

1 answer

0


Well, the solution was to use the function $watch angular. basically I did.

         $scope.$watch('vetorPrincipal['+cont+']', function() {
            //  alert(JSON.stringify(likkkk));
            console.log(cont);
            // alert($scope.likkkk);
            paraExibirGrafico();
         });

var cont ; \\ Essa var diz o tamanho do vetor. So it has a change in the last position of the vector the method paraExibirGrafico() and called, passed the vector in the correct way.

Browser other questions tagged

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