A custom filter is exactly the right answer. A stub for it would look something like this:
angular
.module('myApp', [])
.filter('myFilter', function () {
return function(input, query) {
var result = [];
// Now do whatever you want to create the 'result' array
// input will contain the source to the ng-repeat, categories
// query will contain whatever you gave it as a parameter - see below
// You should return an array of items. Each item will become 'entry' in the ng-repeat
return result;
};
});
and you would use it like this:
<div class="whatever" ng-repeat="entry in categories | myFilter:someParameter track by $index"></div>
Note that you can set $scope.someParameter = 'A'; and that will be passed into your filter as query.
Also, note that your filter is just like any other Angular module now. It can do a lot of clever things, like asking for a service to be injected that it can get things like subcategory data from. But be aware that this is a performance sensitive section of code. Your filter will get run a lot more than you expect because many things will trigger Angular to verify that this list has not changed. Therefore you should make this as efficient as possible.