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.
Here's another solution that you can use, with the help of a little jQuery:
Add a function called
showMe
to your controller:And then in your HTML, change the following from:
to:
If you want to hide the
p
elements by default, you can just add a little CSS:JSBin: http://jsbin.com/fegevoyoda/2/
All the examples are in this js fiddle, and a bit more elaborated.
Also, note that jquery is not used, I greatly recommend not to use jquery in your AngularJs code.
AngularJs include jQuery lite accessible by the
angular.element
method. You should use it for any dom manipulation, if it doesn't provide you enough functionality, then think about creating a directive.Look at this controller for more insight:
You can do like this :