I'm trying to create an index of shops, showing them grouped by category, so i have two ng-repeat, one for the categories and another for the shops
i have an array for the categories (['cat1', 'cat2', ..])
and another with the shops ([{name: 'shop1', categories: ['cat2', 'cat3']}, ..])
Here's the HTML Code for the repeaters:
<div ng-repeat="categoria in categorias | filter:categorySearch:strict">
<h3>{{categoria}}</h3>
<hr width="70%" align="left">
<table style="text-align: center;" class="col-xs-12 col-sm-12 col-md-12 table table-bordered table-striped" class="tabla_tiendas">
<tr ng-repeat="tienda in tiendas | filter:{agregada: 'false'} | filterByCategory:categoria:tienda" >
<td class="col-xs-4 col-sm-4 col-md-4 tienda-{{tienda.seleccionada}}"><input type="checkbox" ng-change="setPosition(tienda, tienda.seleccionada)" ng-model="tienda.seleccionada" value="{{tienda.id}}"></td>
<td class="col-xs-4 col-sm-4 col-md-4 tienda-{{tienda.seleccionada}}">{{tienda.nombre}}</td>
<td class="col-xs-4 col-sm-4 col-md-4 tienda-{{tienda.seleccionada}}">{{tienda.categorias}}</td>
</tr>
</table>
</div>
Here's the Angular Code:
app.filter('filterByCategory', function(tienda, categoria){
return function(tienda, categoria){return _.contains(tienda.categorias, categoria);};
});
And finally here are the errors:
Error: Circular dependency:
at Error (<anonymous>)
at Object.c [as get] (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js:26:368)
at http://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js:108:41
at l (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js:70:141)
at Oc.fa (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js:74:463)
at k (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js:69:505)
at Oc (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js:75:29)
at http://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js:78:241
at Object.e.$watchCollection (http://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js:88:58)
at http://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js:156:40 <!-- ngRepeat: tienda in tiendas | filter:{agregada: 'false'} | filterByCategory:categoria:tienda --> angular.min.js:63
(anonymous function) angular.min.js:63
(anonymous function) angular.min.js:53
l angular.min.js:44
e angular.min.js:39
e angular.min.js:39
e angular.min.js:39
e angular.min.js:39
(anonymous function) angular.min.js:38
(anonymous function) angular.min.js:157
(anonymous function) angular.min.js:89
e.$digest angular.min.js:89
e.$apply angular.min.js:91
(anonymous function) angular.min.js:152
(anonymous function) angular.min.js:23
o angular.min.js:6
c
What is causing the circular dependency and how can i break it? i'm also open to another solution, but it can change the data architecture
Edit:
Here i have a jsFiddle with the problem: http://jsfiddle.net/truca/HB7LU/1458/ (if i use the filter "filterByCategory" i get the circular dependency, if i use the filter "filterByCategoryScope" i dont get the parameter category, so i can't filter)
tienda
model also? – Maxim Shoustin Dec 24 '13 at 21:05angular.js
instead ofangular.min.js
and use non-minified versions of your script, you will find it easier to identify which variables are which in the error. – Andrew Counts Dec 24 '13 at 21:52