angular-filter icon indicating copy to clipboard operation
angular-filter copied to clipboard

Using groupBy in a directive - updating model of one directive instance causes change in another directive instance

Open jimmygchen opened this issue 10 years ago • 2 comments

Not sure if I'm doing anything wrong, but when I use groupBy with ng-repeat in my directive, updating model state of one directive instance "sometimes" updates the model of another instance of the same directive. I'm using isolated scope for the directive, so I'm guessing it might be related to the groupBy result being cached?

Please see this plunker: http://plnkr.co/edit/QIIWma?p=preview

Thanks!

jimmygchen avatar Jul 23 '15 11:07 jimmygchen

Thanks @jchen86, I'll take a deep look later on.

a8m avatar Jul 23 '15 12:07 a8m

Thanks! Looks like this particular scenario is related to how hashKeys are generated for caching - when two equivalent collections are passed to the filter, the same cached object is returned (due to same hash key) , causing the two directive instances to referencing the same object.

I'm not sure if there's a nice solution for this, the alternatives I can think of are either storing a reference of the collection in the cache also (not sure how efficient this would be), or not use caching at all. In this particular scenario, caching doesn't seem useful since the serialized collection changes. Could we make caching optional for this filter?

jimmygchen avatar Jul 23 '15 14:07 jimmygchen