Dynamic ng-repeat filter

Asked

Viewed 963 times

2

I need to insert a dynamic filter, which comes from a select, into my ng-repeat

select ng-model="campoBusca"

input type="text" ng-model="busca"

ng-repeat="funcionario in funcionarios | filter: { campoBusca: busca}"

but not for sure, some other alternative?

1 answer

1

Could you specify more your doubt ? is half vacant.

If it really is what I understood, the solution below should solve:

$scope.campoBusca= {campo1:'', campo2:''}


<ng-model="campoBusca[selecionado]">
<ng-repeat="funcionario in funcionarios | filter: { campoBusca: busca}" >

Follow an example (already existing): Jsfiddle

  • That is, but when changing the filter it must empty the other fields, for example the field 1 is selected and has as value "John", when selecting the field 2 it must change the value of the field 1 to ""

  • In the function of the example, $scope.changeFilterTo you can check which is the type of the parameter, and then clear the other fields of the $scope.search, simple

Browser other questions tagged

You are not signed in. Login or sign up in order to post.