O'Reilly logo

Learning AngularJS by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required