Angular ng-repeat with array length condition
angularjs, angularjs-ng-repeat, html, javascript
Solution
Try:
<div ng-repeat="thumb in photos" ng-if="photos.length > 1"></div>
if the `ng-if` condition is not satisfied those elements will be removed from the DOM. See http://docs.angularjs.org/api/ng/directive/ngIf for further reference.
Problem
I want the `ng-repeat` to run only when the `photos.length > 1` Doing this doesn't seem to work: `<div ng-repeat="thumb in photos | photos.length > 1">` Is there any quick trick / elegant way to do this? I just need to check for array length and nothing else fancy. I would hate to duplicate the array to another array by doing something like this ``` if (oldArray.length > 1) newArray = photos; else newArray = []; ``` ...and then do `ng-repeat` on `newArray`. This seems inefficient. Thanks.