I'm working on creating a filter to sort through the items displayed in a table. Specifically, I want to filter out items based on a certain property value that may change depending on user input. I have attempted the following approach and it seems to be functioning correctly. For example, I am looking to display all cities in my array of countries that are not named Stockholm or Gothenburg.
<table>
<tr ng-repeat="city in cities | filter: name:'!'+'Stockholm' || 'Gothenburg'">
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
</table>
However, I would like to achieve this programmatically by using a function to generate the filter, but I am facing difficulties in making it work.
<table>
<tr ng-repeat="city in cities | filter: getFilter()">
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
</table>
$scope.getFilter = function () {
var filter = {};
if (something) {
filter['name'] = '!' + 'Stockholm';
}
if (somethingElse) {
filter['name'] += ' ||' + 'Gothenburg';
}
return filter;
}