I am trying to have a grid of images, when clicked the image is hid from the grid and shown featured at the top.
HTML:
<div ng-controller="imageCtrl">
<div class="row">
<img ng-show="selected" src="{{selected.img}}" alt="">
<p ng-show="selected">{{selected.des}}</p>
</div>
<div class="row">
<div ng-repeat="(id, image) in images" class="col-sm-4">
<a ng-click="clicked(id)"><img src="{{image.img}}" alt=""></a>
</div>
</div>
</div>
And my controller:
light.controller('imageCtrl', function($scope){
$scope.images = [{img: '',des: ''},{img: '',des: ''},{img: '',des: ''}];
$scope.selected = $scope.images[0];
$scope.clicked = function(id){
selected = $scope.images[id];
};
});
Currently the first image is shown but when I click on other images nothing happens. Anybody have any tips as to what I'm doing wrong? Thank You!
(x,y) in zsyntax inng-repeat- instead just useng-repeat="image in images"and then use the$indexvariable, which is available inside anng-repeat, as the replacement for your currentid.clicked($index)and in your function you can keepidas is.