Error: Cannot read property 'remove' of undefined
I was getting this for awhile and tracked it down to angular-repeat-n...
In my template I do something like this...
ng-repeat-n="(whatever.accountTotalRowCount-whatever.accountRows.length)"
Where both numbers could be 0.
In the for loop at line 38 this can make the i -1 which can't be removed, so it throws:
TypeError: Cannot read property 'remove' of undefined
at Object.fn (angular-repeat-n.js:40)
at n.$digest (angular.js:14308)
at n.$apply (angular.js:14571)
at l (angular.js:9698)
at M (angular.js:9888)
at XMLHttpRequest.F.onload (angular.js:9829)(anonymous function) @ angular.js:11655(anonymous function) @ angular.js:8596n.$digest @ angular.js:14326n.$apply @ angular.js:14571l @ angular.js:9698M @ angular.js:9888F.onload @ angular.js:9829
My hacky fix is to just add this in the first line of the for loop:
if (i===-1) return;
So why the heck would I ever want to do ng-repeat-n="0" ?
I'm basically doing a table which lazy loads data in from a RESTful service. There's a requirement for the empty rows to be available... because requirements!
So I do something hacky like this:
<tr ng-repeat="row in accountRows">
<td>{{ row.id }}</td>
<td>{{ row.name }}</td>
<td>{{ row.whatever }}</td>
</tr>
<tr ng-repeat-n="(accountTotalRowCount-accountRows.length)">
<td colspan="3"> </td>
</tr>
So if there are 0 remaining this will cause that error message.
Thanks for the info here. I'm not sure whether it would be more appropriate to do nothing and absorb the error or to just throw a more understandable error (e.g. "cannot repeat element -1 times").