\$\begingroup\$
\$\endgroup\$
0
Is there any easier/shorter/better way to do the marked part?
<body ng-app="">
Apple <input type="checkbox" ng-model="apple" aria-label="Toggle ngHide"><br/>
Banana <input type="checkbox" ng-model="banana" aria-label="Toggle ngHide"><br/>
<div>
<!-- This part-->
<div ng-show="apple || banana">
You want to buy:
<span>
<span ng-show="apple">Apple</span>
<span ng-show="banana">Banana</span>
</span>
</div>
<!-- This part-->
</div>
</body>
200_success
145k22 gold badges190 silver badges478 bronze badges
asked Aug 11, 2015 at 9:23
1 Answer 1
\$\begingroup\$
\$\endgroup\$
1
Better and more performance oriented solution will be to use ng-if instead of ng-show. Although it doesn't matter with such few items on scope but with huge/big data its better to use ng-if.
<body ng-app="">
Apple <input type="checkbox" ng-model="apple" aria-label="Toggle ngHide"><br/>
Banana <input type="checkbox" ng-model="banana" aria-label="Toggle ngHide"><br/>
<div>
<div ng-if="apple || banana">
You want to buy:
<span>
<span ng-if="apple">Apple</span>
<span ng-if="banana">Banana</span>
</span>
</div>
</div>
</body>
-
\$\begingroup\$ I was thinking more syntactically if you could make it shorter \$\endgroup\$Viktor Mellgren– Viktor Mellgren2015年08月11日 11:03:28 +00:00Commented Aug 11, 2015 at 11:03
default