1
\$\begingroup\$

Is there any easier/shorter/better way to do the marked part?

plnkr

<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
\$\endgroup\$
0

1 Answer 1

2
\$\begingroup\$

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>
answered Aug 11, 2015 at 10:54
\$\endgroup\$
1
  • \$\begingroup\$ I was thinking more syntactically if you could make it shorter \$\endgroup\$ Commented Aug 11, 2015 at 11:03

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.