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

filter comparator params order #5365

Closed
Javabien opened this issue Dec 10, 2013 · 2 comments
Closed

filter comparator params order #5365

Javabien opened this issue Dec 10, 2013 · 2 comments
Milestone

Comments

@Javabien
Copy link

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 ===
@ghost ghost assigned tbosch Dec 11, 2013
royling added a commit to royling/angular.js that referenced this issue Jan 3, 2014
fix wrong param order in doc for filter comparator
doc function param for filter expression

Closes angular#5365
@Javabien
Copy link
Author

@royling
Copy link
Contributor

royling commented Jan 17, 2014

@Javabien modified the comparator signature to $scope.basiccomparator = function(actual, expected), you will get the right thing. See this http://plnkr.co/edit/0euZdbBQRbAGHOsLimFi

jamesdaily pushed a commit to jamesdaily/angular.js that referenced this issue Jan 27, 2014
fix wrong param order in doc for filter comparator
doc function param for filter expression

Closes angular#5365
Closes angular#5611
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this issue Jan 27, 2014
fix wrong param order in doc for filter comparator
doc function param for filter expression

Closes angular#5365
Closes angular#5611
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants