Vector gets values wrong

0

Hello, I'm using angular and pouchdb to insert value into a vector. but currently with the code below at the time of using the command console.log(vetorPrincipal); it returns so

Thecorrectwaywouldbetoreturn

Mycodeistheonebelow.

varvetorPrincipal=[];insereNoVetor();console.log(vetorPrincipal);functioninsereNoVetor(){//verificasevariaveisestãopreenchidas,seestiverementãoZeraif(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);
         });
       });
     });
   }
 }
    
asked by anonymous 18.08.2016 / 19:37

1 answer

0

Well, the solution was to use the $watch of angular function. 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 that there is a change in the last position of the vector the method paraExibirGrafico() is called, passed the vector correctly.

    
22.08.2016 / 17:56