0

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!

1
  • 1
    what php doin in the html? Commented Aug 10, 2017 at 16:53

2 Answers 2

2

use ng-repeat like this:

ng-repeat="image in gallery | filter:{ type: 'GEN'} | limitTo:'4'"
Sign up to request clarification or add additional context in comments.

Comments

1

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.