Issue
I have two filters (buildFilter:searchText && filter:searchText) and I want to apply them conditionally when searchText.APP.VERSION is true apply buildFilter:searchText else filter:searchText I'm trying to use ternary operator but it's not working, not sure what are the different ways to achieve this.
<tbody ng-repeat="result in filtered = (vm.ProcessedResults | searchText.APP.VERSION ? buildFilter:searchText : filter:searchText) track by result.ENV_ID">
Kinda stuck on this, any help will helpful. Thanks
Solution
try this
<tbody ng-repeat="result in filtered | filter: (!searchText.APP.VERSION ? searchText:'') | buildFilter:(searchText.APP.VERSION ? searchText:'') track by result.ENV_ID">
this is an example of using multiple filters based on condition
<div ng-controller="MainCtrl">
<ul>
<li ng-repeat="mentor in mentors | filter:(search ? searchText:filterFn )">{{mentor}}</li>
</ul>
</div>
script
var app = angular.module('myApp', []);
function MainCtrl( $scope ) {
$scope.mentors = [ 'Jonathan', 'Nathan', 'Chris', 'Brian', 'Timothy' ];
$scope.searchText = "j";
$scope.search = false;
$scope.filterFn = function(car)
{
// Do some tests
if(car == 'Nathan')
{
return true; // this will be listed in the results
}
return false; // otherwise it won't be within the results
};
}
https://jsfiddle.net/9gp3w7vx/
Answered By - Khalil
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.