Using Filters to Implement Ordering and Filtering
A very common use of filters is to order or filter out dynamic elements built using the ng-repeat
directive from JavaScript arrays. This section provides an example of implementing orderBy
filters to generate a table that can be sorted by column and filtered by a string from an <input>
element.
Listing 5.9 implements a controller that defines the $scope.planes
array to use as input data in the scope. Since you do not want to alter the actual model data when sorting and filtering, line 12 adds the $scope.filteredPlanes
property to store the filtered array.
Notice that line 13 sets a $scope.reverse
value to keep track of the sort direction. Then line 14 sets a $scope.column
value to keep track of ...
Get Learning AngularJS now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.