filter (filter)

Improve this Doc View Source filter

  1. filter in module ng

Selects a subset of items from array and returns it as a new array.

Usage

In HTML Template Binding

{{ filter_expression | filter : expression : comparator}}

In JavaScript

$filter('filter')(array, expression, comparator)

Arguments

Param Type Details
array Array

The source array.

expression stringObjectfunction()

The predicate to be used for selecting items from array.

Can be one of:

  • string: The string is evaluated as an expression and the resulting value is used for substring match against the contents of the array. All strings or objects with string properties in array that contain this string will be returned. The predicate can be negated by prefixing the string with !.

  • Object: A pattern object can be used to filter specific properties on objects contained by array. For example {name:"M", phone:"1"} predicate will return an array of items which have property name containing "M" and property phone containing "1". A special property name $ can be used (as in {$:"text"}) to accept a match against any property of the object. That's equivalent to the simple substring match with a string as described above. The predicate can be negated by prefixing the string with !. For Example {name: "!M"} predicate will return an array of items which have property name not containing "M".

  • function(value): A predicate function can be used to write arbitrary filters. The function is called for each element of array. The final result is an array of those elements that the predicate returned true for.

comparator function(actual, expected)trueundefined

Comparator which is used in determining if the expected value (from the filter expression) and actual value (from the object in the array) should be considered a match.

Can be one of:

  • function(actual, expected): The function will be given the object value and the predicate value to compare and should return true if the item should be included in filtered result.

  • true: A shorthand for function(actual, expected) { return angular.equals(expected, actual)}. this is essentially strict comparison of expected and actual.

  • false|undefined: A short hand for a function which will look for a substring match in case insensitive way.

© 2010–2016 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://code.angularjs.org/1.2.32/docs/api/ng/filter/filter

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部