Skip to content

Commit

Permalink
fix(marker.js): add check to scope teardown (#315)
Browse files Browse the repository at this point in the history
On a $scope.$destroy the unregisterHandler function is called. This function removes all the eventListeners.
The properties object that these listeners are attached to, might not exist. So during the teardown, an error will be raised.

This fixes issue #314
  • Loading branch information
njirem authored and juristr committed Sep 2, 2016
1 parent f9eef55 commit f2a72ad
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/directives/marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ angular.module('openlayers-directive').directive('olMarker', function($log, $q,
};

function unregisterHandlers() {
if (!scope.properties) { return ; }
// Remove previous listeners if any
map.getViewport().removeEventListener('mousemove', scope.properties.handleInteraction);
map.getViewport().removeEventListener('click', scope.properties.handleTapInteraction);
Expand Down
23 changes: 23 additions & 0 deletions test/unit/markerSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';
/*jshint -W117 */
/*jshint globalstrict: true*/
/* jasmine specs for directives go here */

describe('Directive: openlayers marker', function() {
var $compile = null;
var scope;

beforeEach(module('openlayers-directive'));
beforeEach(inject(function(_$compile_, $rootScope) {
$compile = _$compile_;

scope = $rootScope.$new();
}));

it('should not error on $scope.$destroy', function() {
var element = angular.element('<openlayers><ol-marker lat="0" lon="0"></ol-marker></openlayers>');
element = $compile(element)(scope);
scope.$digest();
expect(function() { scope.$destroy(); }).not.toThrow();
});
});

0 comments on commit f2a72ad

Please sign in to comment.