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

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.