Angular ng - if counting divs

I have multiple filters using ng-show

and I need to show a div when all others are hidden.

I am creating a function to count divs, it works, but when all divs are hidden, the div is only shown in the next interaction, eg.

I have 3 divs, Plan 1, Plan 2 and Plan 3 ... when I find for Plan 4 all divs hidden, but only I put more than one ex: Plan 44 ... this is what the div appears.

ng repeat

<div  ng-repeat="plan in plans | filter:palavra_chave" >
    <div  class="plano" ng-if="plan.value <= filter_value && plan.download_mb >= filter_mb && plan.fee <= filter_adesao">
 </div>

      

div I am trying to show

<div ng-if="div() == 0" class="card-panel center ">

      

Angular function for counting divs

$scope.contar_div = function()
{
    return conta_planos();
}

      

this is the function for counting divs

function conta_planos()
  {
      return $('.plano').length
  }

      

conta_planos is a javascript function in a view

+3


source to share


1 answer


I decided to change the way I filter items

new ng-repeat

<div  ng-repeat="plan in plans |filter:palavra_chave |filter: search as lista " >

      

angular search function



$scope.search = function(plan) {
    if ((plan.value <= $scope.filter_value && plan.download_mb >= $scope.filter_mb && plan.fee <= $scope.filter_adesao)){
        return true;
    }
    return false;
};

      

div to show

<div ng-if="lista.length == 0" class="card-panel center ">

      

thanks for the help.

+1


source







All Articles