I am very new to AngularJS and am trying to design a row with 3 elements per row in an ng-repeat. When the user clicks on one of the row elements, below it another row should show up based on the ng-show i have in place. I separated each row into different objects and placed the show between the lines. My question here is, can I ng-click in one of my rows and hide the row that may have been clicked in another row?
My thought process is to ng-click the selected and show the selected's information. Anything on the same row is chill because they will all bind to the same ng-show thats for the row. But the problem comes when I click 1 element in one row, and then click another element in the second row. both divs show, but I'd only like the one I clicked to show.
Any thoughts? I've done hella stuff, and have gotten close in some regard, but not exactly the UX i've been looking for. Thanks, and sorry for being a noob. At a company where no one has angular experience, its awesome that I can come here seeking help.
<div ng-controller="oneCtrl">
<div class="row">
<div ng-repeat="image in images" class="span4 padding-bottom30">
<a href rollover ng-click="select(image)">
<img class="img-responsive padding-top30" ng-src={{image.img}}/>
</a>
</div>
</div>
<div ng-show=selected>
<div class="row">
<div class="span4 padding-top30">
<h3 class="mont margin-top0">{{selected.name}}</h3>
<p><b>Mission Statement</b></p>
<p>{{selected.info}}</p>
<a href={{selected.site}}><button class="btn btn-colour-red pull-left">VISIT SITE</button></a>
</div>
<div class="span8 padding-top30">
<img class="img-responsive" ng-src={{selected.photo}}/>
</div>
</div>
</div>
<div class="row">
<div ng-repeat="pics in images" class="span4 padding-bottom30">
<a href ng-click="select(pics)">
<img class="img-responsive padding-top30" ng-src={{pics.img}}/>
</a>
</div>
</div>
<div ng-show=selected>
<div class="row">
<div class="span4 padding-top30">
<h3 class="mont margin-top0">{{selected.name}}</h3>
<p><b>Mission Statement</b></p>
<p>{{selected.info}}</p>
<a href={{selected.site}}><button class="btn btn-colour-red pull-left">VISIT SITE</button></a>
</div>
<div class="span8 padding-top30">
<img class="img-responsive" ng-src={{selected.photo}}/>
</div>
</div>
</div>
</div>
You are using ng-show="selected"
in both the section's DIVs. It is one variable, and hence controls hiding or showing of the sections when you click on an image. That is the reason it keeps showing both DIVs. To solve this, you need to use two variables, may be selected1
and selected2
and control it based on which image you click (row 1 or row 2).
Check this plunker .
I hope this helps.