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 23.5 implements a controller that defines the $scope.cameras
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 9 adds the $scope.filteredCameras
property to store the filtered array.
Notice that line 10 sets a $scope.reverse
value to keep track of the sort direction. Then line 11 sets a $scope.column
value to keep track ...
Get Node.js, MongoDB, and AngularJS Web Development 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.