0

I'm trying to use filter who gonna change depending on a click or write on an input.

<input
  name="hotelinput"
  type="text"
  ng-keydown="changeFilterToKeyPressed()"
  ng-click="changeFilterToClicked()">

<div ng-repeat="hotel in filteredHotels = (hotels | VARIABLEFILTER | orderBy: 'country') track by $index">
    ...
</div>

I know that you can do filter:variable and change it in the controller but I need to change the full filter for one of my custom filters every time.

0

2 Answers 2

0

You need ngChange instead of ngClick

<input
  name="hotelinput"
  type="text"
  ng-model="filterKey"
  ng-change="changeFilterToKeyPressed()"
  ng-focus="changeFilterToClicked()">

and update your function changeFilterToKeyPressed

$scope.changeFilterToKeyPressed = function() {
    $scope.VARIABLEFILTER = someUpdatesWhichYouWant($scope.filterKey); //You can use filterKey on any change
}
Sign up to request clarification or add additional context in comments.

3 Comments

I don't understand what are you trying to do and how is related to my question.
no problem if its not a answer of your problem then im going to delete it.
I don't know if it's an answer or not, I just didn't understand. A better explanation is appreciated.
0

I didn't tested it but something like this could be possible

JS

if(x){
  $scope.VARIABLEFILTER = $filter('myCustomFilter')
} else {
  $scope.VARIABLEFILTER = $filter('myCustomFilter2')
}

I made it to work and rewrote the filter I once did in other question http://plnkr.co/edit/LuA3hYr7mImihYnVIxqQ

  .filter('applyFilter', function($filter) {
    return function(input, filterToApply) {
      return filterToApply === undefined ? input : $filter(filterToApply)(input)
    }
  })

I hope that's what you were looking for

1 Comment

Looks like didn't work. And I need to pass parameters anyway. Like myCustomFilter:anything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.