I am new to AngularJS and I am creating a small car rental application that pulls in some kind of JSON and displays various bits of this data via ng-repeat, with several filters
<article data-ng-repeat="result in results | filter:search" class="result"> <header><h3>{{result.carType.name}}, {{result.carDetails.doors}} door, £{{result.price.value}} - {{ result.company.name }}</h3></header> <ul class="result-features"> <li>{{result.carDetails.hireDuration}} day hire</li> <li data-ng-show="result.carDetails.airCon">Air conditioning</li> <li data-ng-show="result.carDetails.unlimitedMileage">Unlimited Mileage</li> <li data-ng-show="result.carDetails.theftProtection">Theft Protection</li> </ul> </article> <h2>Filters</h2> <h4>Doors:</h4> <select data-ng-model="search.carDetails"> <option value="">All</option> <option value="2">2</option> <option value="4">4</option> <option value="9">9</option> </select> <h4>Provider:</h4> Atlas Choice <input type="checkbox" data-ng-model="search.company" ng-true-value="Atlas Choice" ng-false-value="" value="Atlas Choice" /><br> Holiday Autos <input type="checkbox" data-ng-model="search.company" ng-true-value="Holiday Autos" ng-false-value="" value="Holiday Autos" /><br> Avis <input type="checkbox" data-ng-model="search.company" ng-true-value="Avis" ng-false-value="" value="Avis" /><br>
Now I want to create a custom filter in my controller, which can iterate over the elements in my ng-repeat and return only those elements that meet certain criteria - for example, I can create an array of values based on which the "flag" provider "is checked, and then evaluates every ng-repeat element, I just can't figure out how to do this, though in terms of syntax - can anyone help?
Here is my plunker: http://plnkr.co/edit/lNJNYagMC2rszbSOF95k?p=preview
angularjs ng-repeat angular-filters
ParkerDigital May 15, '13 at 10:46 2013-05-15 10:46
source share