0

I am using angular $filter to take non matching objects from two string.

i have written below code to iterate .

 angular.forEach(this.members, function (value: any, index: any) {
                var person = this.$filter('filter')(this.allPersonnel, { Id:    value.Member.Id })[0];
                console.log(person);
                this.validPerson.push(person); // Filter 
            });

As you can see i am not not able to add "Not equal to" condition. I tried with "Id:'!value.Member.Id'"

but it is considering as string.

Could you guys please tell me a way to do this. I am using Typescript angular.

ppovoski
  • 4,553
  • 5
  • 22
  • 28

2 Answers2

0

Create your own custom filter and use it that one instead.

Here is an example of how to create one: Creating a custom Angular filter with TypeScript

Community
  • 1
  • 1
Tome Pejoski
  • 1,582
  • 2
  • 10
  • 34
  • Thanks for your reply. I am looking for the logic to find not matching nodes from two array. I know how to create custom filter. I was looking something like C# linq - `var list1IDs = new HashSet(List1.Select(s => s.ID)); var results = List2.Where(m => !list1IDs .Contains(m.ID));` – Onkarraj Ambatwar Nov 21 '16 at 08:56
  • Ahh OK. Then the easiest way to do that is by using a library like Lodash. There you have a method like https://lodash.com/docs/#differenceBy where you can put your logic and get the wanted result. – Tome Pejoski Nov 21 '16 at 09:05
  • Here is how to import Lodash into your project http://stackoverflow.com/questions/34660265/importing-lodash-into-angular2-typescript-application. – Tome Pejoski Nov 21 '16 at 09:07
0

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="namesCtrl">
<p><input type="button" value="Find Match" ng-click="FindUniqueRecords()"/></p>
<p> Filtered Records:</p>
<ul>
  <li ng-repeat="x in FilteredRecords">
    {{ x }}
  </li>
</ul>
</div>

<script>
angular.module('myApp', []).controller('namesCtrl',['$scope','$filter', function($scope,ff) {
$scope.FilteredRecords=[];
$scope.FindUniqueRecords=function(){
angular.forEach($scope.CountryCode1,function(value,index){
var foundMatch=ff('filter')($scope.CountryCode2,value);
if(foundMatch.length==0){
$scope.FilteredRecords.push(value);
}
});
angular.forEach($scope.CountryCode2,function(value,index){
var foundMatch=ff('filter')($scope.CountryCode1,value);
if(foundMatch.length==0){
$scope.FilteredRecords.push(value);
}
});

};
$scope.CountryCode1= [
        'Aus',
        'NZ'
    ];
$scope.CountryCode2= [
        'Aus',
        'Ind',
        'Eng'
    ];

}]);
</script>

</body>
</html>

I tried this logic to find unique list from two array.

Anil
  • 1,669
  • 5
  • 19
  • 44