Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

filter comparator params order #5365

Closed
Closed
@Javabien

Description

@Javabien

There is a mistake in the documentation about the orders of the parameters. It says ...

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(expected, actual): 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.

Actually, when I tried it's the opposite: function(actual, expected) not function(expected, actual)

Example from plunkr:

=== index.html ===

<!DOCTYPE html>
<html ng-app="plunker">

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
    <script data-require="angular.js@1.2.4" src="http://code.angularjs.org/1.2.4/angular.js" data-semver="1.2.4"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="MainCtrl">
  List:
    <p ng-repeat="item in list | filter:basicfilter:basiccomparator">- {{item.test}}</p>
  </body>

</html>
\```
=== index.html ===


=== app.js ===
var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {

  $scope.list = [{"test":"#1 - Actual from list"}, {"test": "#2 - Actual 2 from list"}];

  $scope.basicfilter = {
    $ : '',
    test : 'Expected Value from Filter'
  };

  $scope.basiccomparator = function(expected, actual) {
    console.log('Expected from filter: ', expected);
    console.log('Actual from list :', actual);
    return true;
  }

});
=== app.js ===

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions