Reputation: 1221
I am new to angularJS. I have the following code:
<div class="col-sm-3 col-xs-6" ng-repeat="image in gallery | limitTo:'4'">
<a href="#"><img ng-src="
<?php echo '...' ?>{{pack.hotels.current.images[$index+1].path}}"
alt="Image" class="img-responsive"></a>
</div>
Currently I have an array of objects which have 2 properties: type and path. In the ng-repeat I iterate through all the objects. I would like to iterate only through objects in array that have the property type==="GEN"
While debugging, I run:
pack.hotels.current.images.forEach(function(item, count){
if(item.type === "HAB")
console.log(item)
})
How can I rewrite the ng-repeat statement so that it iterates only through elements that have property type="GEN" ? Which filter should I apply? Thank you!
Upvotes: 0
Views: 47
Reputation: 1354
Just add a filter filter: {type:'GEN'}
HTML
<div class="col-sm-3 col-xs-6" ng-repeat="image in gallery | filter: {type:'GEN'}| limitTo:'4'">
<a href="#"><img ng-src="
<?php echo '...' ?>{{pack.hotels.current.images[$index+1].path}}"
alt="Image" class="img-responsive"></a>
</div>
Upvotes: 1
Reputation: 3232
use ng-repeat like this:
ng-repeat="image in gallery | filter:{ type: 'GEN'} | limitTo:'4'"
Upvotes: 2