0

I want to determine whether any ng-repeated element is rendered.

I write this code

<div ng-show="anyRendered">Any has been rendered</div>

 <div ng-show="anyFilterActive">ANY FILTER IS ACTIVE</div>

 <div class="selected-filter-value" ng-if="filter.name && filterCtrl.isActiveFilter(filter)" data-ng-repeat="(name, filter) in filterOptions">
    <span ng-init="anyFilterActive = true;">{{filter.name}}:</span>

</div>

But this code doesn't work. Also I try to write $parent.anyRendered inside ng-repeat.

BILL
  • 4,711
  • 10
  • 57
  • 96

3 Answers3

1

Try with ng-if

<div ng-show="filterOptions.length > 0">Any has been rendered</div>

<div ng-if="filterOptions.length > 0" ng-repeat="(name, filter) in filterOptions">
<span></span>
</div>
Sudharsan S
  • 15,336
  • 3
  • 31
  • 49
0

You must not write code logic in your templates: all the code must be in your controllers, filters, directives and services. The ng-init directive is only here so that you can create aliases to make your templates simpler.

Filters and directives contain "presentation code" and controllers and services contain "business related code".

You could create a filter to know if an object is empty or not (filter code from another question), and use it with ng-if, ng-show...

Resulting template:

<div ng-if="filterOptions|empty">
     Nothing to show! 
</div>
<div ng-repeat="(k, v) in filterOptions">
     {{k}}, {{v}}
</div>
Community
  • 1
  • 1
Eloims
  • 5,106
  • 4
  • 25
  • 41
0

just use $index

<div ng-repeat="(name, filter) in filterOptions">

<span ng-show="$index > 0"></span>

</div>

ngRepeat Docs $index

In the example in the ng-repeat docs u can see the usage of $index

stackg91
  • 584
  • 7
  • 25