How to reduce observers inside AngularJS for ng-show with the same condition

In my HTML, some divwill display with the same condition. I set this condition on ng-showfor everyone div.

<div ng-show="sameCondition1">...data1...</div>
...something else...
<div ng-show="sameCondition1">...data2...</div>
...something else...
<div ng-show="sameCondition1">...data3...</div>

AngularJS will create 3 observers for each ng-show. This may affect performance. Is there a way to reduce the number of observers in this case?

+4
source share
2 answers

, , AngularJS > 1.3.x, someCondition1 , Angular :: :

<div ng-show="::sameCondition1">...data1...</div>
...something else...
<div ng-show="::sameCondition1">...data2...</div>
...something else...
<div ng-show="::sameCondition1">...data3...</div>

, . , 1, CSS. :

<div class="{{sameCondition1 ? '' : 'hide-similar'}}">
    <div class="similar1">...data1...</div>
    ...something else...
    <div class="similar1">...data2...</div>
    ...something else...
    <div class="similar1">...data3...</div>
</div>

CSS:

.hide-similar .similar1 {
    display: none;
}
+5

ng-switch, - varaible (: a == 1, a == 2, a == 3). 3 1.

0

All Articles