AngularJS-filter

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

1 {{ filter_expression | filter : array : expression : comparator}}
View Code

In JavaScript

1 $filter(‘filter‘)(array, expression, comparator)
View Code

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.

  • 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:

  1. -`function(actual, expected)`:
  2. Thefunction will be given the object value and the predicate value to compare and
  3. should returntrueif the item should be included in filtered result.
  4.  
  5. -`true`: A shorthand for`function(actual, expected) { return angular.equals(expected, actual)}`.
  6. thisis essentially strict comparison of expected and actual.
  7.  
  8. -`false|undefined`: A short hand for a function which will look for a substring match incase
  9. insensitive way.

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。