Tutorial by Examples

Filters are a special type of function that can modify how something is printed out to the page, or can be used to filter an array, or a ng-repeat action. You can create a filter by calling the app.filter() method, passing it a name and a function. See the examples below for details on syntax. Fo...
A typical use case for a filter is to remove values from an array. In this example we pass in an array and remove any nulls found in it, returning the array. function removeNulls() { return function(list) { for (var i = list.length - 1; i >= 0; i--) { if (typeof list[i...
Another use case for filters is to format a single value. In this example, we pass in a value and we are returned an appropriate true boolean value. function convertToBooleanValue() { return function(input) { if (typeof input !== 'undefined' && input !== null ...
This example was done in order to demonstrate how you can perform a deep filter in a child array without the necessity of a custom filter. Controller: (function() { "use strict"; angular .module('app', []) .controller('mainCtrl', mainCtrl); function mainCtrl() { ...
By injecting $filter, any defined filter in your Angular module may be used in controllers, services, directives or even other filters. angular.module("app") .service("users", usersService) .controller("UsersController", UsersController); function usersService...
Occasionally you will want to access the result of your filters from outside the ng-repeat, perhaps to indicate the number of items that have been filtered out. You can do this using as [variablename] syntax on the ng-repeat. <ul> <li ng-repeat="item in vm.listItems | filter:vm.myF...

Page 1 of 1