Reputation: 489
Rather than have two blocks of code which are almost identical (the difference being a single ng-show attribute if some data exists), is there a way to avoid the repetition and have ng-show be present on condition that the data is there?
Current pseudo implementation
<div ng-if="data value X exists">
<div ng-show="data binded condition using X">
stuff here... many LoC
</div>
</div>
<div ng-if="data value X doesnt exist">
<div>
EXACT same stuff here but without the ng-show in the div above.
</div>
</div>
This could be much leaner
<div ng-show-attr-here-if-data-value-X-exists="data binded condition using X">
stuff here
</div>
Is this even possible?
I see ng-attr come up often when I google around this topic, but I seem to be having no luck with ng-show, most likely due to my own inexperience.
Thanks in advance.
Upvotes: 0
Views: 204
Reputation: 9486
Just use ng-if and ng-show on same element:
<div>
<div ng-if="data value X exists" ng-show="data binded condition using X">
stuff here... many LoC
</div>
</div>
Upvotes: 0