Skip to content

Commit

Permalink
fix(angular.element): do not break on cleanData() if _data() retu…
Browse files Browse the repository at this point in the history
…rns undefined

This shouldn't happen in supported jQuery versions (2+), but if someone
uses the unsupported 1.x version the app will break. The change that
causes this new behavior was introduced in b7d396b.

Even though jQuery 1.x is not supported, it is worth avoiding the
unnecessary breakage (given how simple).

Fixes angular#16641

Closes angular#16642
  • Loading branch information
gkalpak committed Jul 23, 2018
1 parent 204f9ff commit e500fb6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -1909,7 +1909,7 @@ function bindJQuery() {
jqLite.cleanData = function(elems) {
var events;
for (var i = 0, elem; (elem = elems[i]) != null; i++) {
events = jqLite._data(elem).events;
events = (jqLite._data(elem) || {}).events;
if (events && events.$destroy) {
jqLite(elem).triggerHandler('$destroy');
}
Expand Down
6 changes: 6 additions & 0 deletions test/jqLiteSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,12 @@ describe('jqLite', function() {
expect(jqLite(c).data('prop')).toBeUndefined();
});

it('should not break on cleanData(), if element has no data', function() {
var selected = jqLite([a, b, c]);
spyOn(jqLite, '_data').and.returnValue(undefined);
expect(function() { jqLite.cleanData(selected); }).not.toThrow();
});


it('should add and remove data on SVGs', function() {
var svg = jqLite('<svg><rect></rect></svg>');
Expand Down

0 comments on commit e500fb6

Please sign in to comment.