Hi,
I have an ng-repeat with an orderBy filter to sort it. The orderBy filter is supplied a function that extracts a property for sorting. The function also uses another property, on the parent scope, to control exactly what property is extracted.
Simplified, pseudo-code:
<div ng-repeat="item in items | orderBy:myFilterFunction">
...
</div>
function Controller() {
...
$scope.whichPropertyToSortBy = 'x';
$scope.myFilterFunction = function(item) {
if ($scope.whichPropertyToSortBy == 'x') {
return some calculated expression;
}
else
{
return some other calculated expression;
}
}
}
The problem is, when $scope.whichPropertyToSortBy is changed, as the result of some other action like a button click, Angular does not reorder the items. How can I arrange things so Angular realises that myFilterFunction has a dependency on whichPropertyToSortBy? Or can I force an update of the ng-repeat somehow?
I've come to Angular from Knockout, where it's fairly trivial to express these kind of dependencies. It seems like Angular's dirty-checking works well for models with primitive properties, but not ones where things need to be computed dynamically. Maybe I just need to shift my mindset as to how to handle these sort of things in Angular?