Skip to content

Commit d6945e6

Browse files
Merge branch 'kyletheninja-patch-1' of https://github.com/kyletheninja/angularUtils into kyletheninja-kyletheninja-patch-1
2 parents 443898a + afdc34e commit d6945e6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/directives/pagination/dirPagination.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
// Now that we have access to the `scope` we can interpolate any expression given in the paginationId attribute and
6969
// potentially register a new ID if it evaluates to a different value than the rawId.
7070
var paginationId = $parse(attrs.paginationId)(scope) || attrs.paginationId || DEFAULT_ID;
71+
// In case rawId != paginationId we deregister using rawId for the sake of general cleanliness
72+
// before registering using paginationId
73+
paginationService.deregisterInstance(rawId);
7174
paginationService.registerInstance(paginationId);
7275

7376
var repeatExpression = getRepeatExpression(expression, paginationId);
@@ -102,6 +105,12 @@
102105

103106
// Delegate to the link function returned by the new compilation of the ng-repeat
104107
compiled(scope);
108+
109+
// When the scope is destroyed, we make sure to remove the reference to it in paginationService
110+
// so that it can be properly garbage collected
111+
scope.$on('$destroy', function destroyDirPagination() {
112+
paginationService.deregisterInstance(paginationId);
113+
});
105114
};
106115
}
107116

@@ -520,6 +529,10 @@
520529
}
521530
};
522531

532+
this.deregisterInstance = function(instanceId) {
533+
delete instances[instanceId];
534+
};
535+
523536
this.isRegistered = function(instanceId) {
524537
return (typeof instances[instanceId] !== 'undefined');
525538
};

0 commit comments

Comments
 (0)