Skip to content

Error: Cannot read property 'remove' of undefined #6

@pjobson

Description

@pjobson

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">&nbsp;</td>
</tr>

So if there are 0 remaining this will cause that error message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions