From 3da4194f98fa0c1ad1e5ab159719e4b25799e6d4 Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Sat, 16 Jun 2012 13:04:40 -0700 Subject: fix($location): url rewriting if element was removed When user clicks a link, $location needs to intercept this event. The doesn't have to be target element of the DOM event, so it needs to traverse the DOM, to find first parent. If the target element was removed from DOM, during the same event, it would throw an exception. This fixes the issue. Closes #1058--- test/ng/locationSpec.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test/ng') diff --git a/test/ng/locationSpec.js b/test/ng/locationSpec.js index 88747dff..cdad1f1f 100644 --- a/test/ng/locationSpec.js +++ b/test/ng/locationSpec.js @@ -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(''); + var button = $rootElement.find('button'); + + button.bind('click', function() { + button.remove(); + }); + browserTrigger(button, 'click'); + })); }); -- cgit v1.2.3