Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS ng-show one condition with multiple elements

I have three divs with an ng-click with a "showMe" boolean. Their paragraphs have an ng-show that evaulates "showMe".

My question is, how can I use one condition to show the paragraph on the div I click? In other words, if I click the first div, I should only see "1", the "2" and "3" parapgraphs should stay hidden. ng-repeat is not an option for this exercise.

Here's a JSBin:

http://jsbin.com/kiwicipabago/1/edit

Thank you.

like image 744
Ryan Avatar asked Mar 15 '26 12:03

Ryan


1 Answers

You can do like this :

<div ng-app="app">
<div ng-controller="AppCtrl">
  <div class="box" ng-click="showMe = 1">
    <p ng-show="showMe ==1">1</p>
  </div>
  <div class="box" ng-click="showMe = 2">
    <p ng-show="showMe==2">2</p>
  </div>
  <div class="box" ng-click="showMe = 3">
    <p ng-show="showMe ==3">3</p>
  </div>
</div>

like image 193
Vijay Avatar answered Mar 18 '26 03:03

Vijay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!