Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix($location): url rewriting if element was removed #1062

Merged
merged 1 commit into from
Jun 21, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,8 @@ function $LocationProvider(){

// traverse the DOM up to find first A tag
while (lowercase(elm[0].nodeName) !== 'a') {
if (elm[0] === $rootElement[0]) return;
elm = elm.parent();
// ignore rewriting if no A tag (reached root element, or no parent - removed from document)
if (elm[0] === $rootElement[0] || !(elm = elm.parent())[0]) return;
}

var absHref = elm.prop('href'),
Expand Down
15 changes: 15 additions & 0 deletions test/ng/locationSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,21 @@ describe('$location', function() {
expect(event.preventDefault).not.toHaveBeenCalled();
});
});


// regression https://github.com/angular/angular.js/issues/1058
it('should not throw if element was removed', inject(function($document, $rootElement, $location) {
// we need to do this otherwise we can't simulate events
$document.find('body').append($rootElement);

$rootElement.html('<button></button>');
var button = $rootElement.find('button');

button.bind('click', function() {
button.remove();
});
browserTrigger(button, 'click');
}));
});


Expand Down