3

I have some filters using ng-show and I need show a div when all others div it's hidden.

I create a function to count divs, it's work but when all divs is hidden the div only show in next interation, for example.

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 one character ex: Plan 44... is that 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'm trying show

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

Angular function to count divs

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

this is the function to count divs

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

conta_planos is a javascript function in view

  • Are your `.plano` elements in angular's scope? Are the `.plano` elements displayed by using `ng-repeat` or something? – devqon Apr 24 '17 at 13:37
  • Your question title and description talks about ng-if but your code uses ng-show. [ng-if documentation](https://docs.angularjs.org/api/ng/directive/ngIf) ngIf differs from ngShow and ngHide in that ngIf completely removes and recreates the element in the DOM rather than changing its visibility via the display css property. – Pedro Perez Apr 24 '17 at 15:22
  • I did not express myself very well, see edit – Gabriel Santos Apr 24 '17 at 17:05

1 Answers1

1

i solved changing how i filter elements

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 help..