Underscore.js causing Angularjs $digest to abort

I'm trying to group an array of objects by the first letter of an arbitrary field name, though I've had this issue other times I've tried to use underscore.js.

Here's an example plunker: http://plnkr.co/edit/xt9ahm1dSLa0xVMxW5QA

I have a list of items ($scope.items) and I'm using an ng-repeat to iterate over them after passing them through some filters. The filter is using underscore.js groupBy to return an object with properties for each group (see example at bottom of app.js).

When I try to use the filter I hit the 10 $digest() iterations reached, Aborting! exception.

I have some idea of why its happening, the filter must be modifying the underlying objects content which AngularJS picks up on and then tries to re-run the filter. I'm not sure where this modification is happening though:

  • Is it something internal to _.js that I can't control?
  • Is there some special setup I have to do before I attempt to process an array in a filter? Some kind of scope.$unwatch?
  • Why does Angularjs's own orderBy not cause this?

As linked by BinaryMuse, this Google Groups link explains why this happens.