diff --git a/demo/demo.html b/demo/demo.html index f470c4a..067b7e4 100644 --- a/demo/demo.html +++ b/demo/demo.html @@ -35,7 +35,7 @@

Marker

google maps-->
+ ui-options="mapOptions" ui-on-finish="myCallback">
diff --git a/demo/demo.js b/demo/demo.js index 9a6fb27..b42948b 100644 --- a/demo/demo.js +++ b/demo/demo.js @@ -12,6 +12,10 @@ angular.module('doc.ui-map', ['ui.map', 'prettifyDirective', 'ui.bootstrap', 'pl $scope.myMarkers = []; + $scope.myCallback = function() { + console.log('callback called'); + }; + $scope.mapOptions = { center: new google.maps.LatLng(35.784, -78.670), zoom: 15, diff --git a/src/ui-map.js b/src/ui-map.js index 7df3e36..d52ff8c 100644 --- a/src/ui-map.js +++ b/src/ui-map.js @@ -40,6 +40,11 @@ model.assign(scope, map); bindMapEvents(scope, mapEvents, map, elm); + + if (attrs.uiOnFinish) { + // call the callback + scope[attrs.uiOnFinish](map); + } } }; }]); diff --git a/test/mapSpec.js b/test/mapSpec.js index 03e738e..ca1af5f 100644 --- a/test/mapSpec.js +++ b/test/mapSpec.js @@ -55,6 +55,18 @@ describe('uiMap', function () { google.maps.event.trigger(scope.gmap, 'dragend'); expect(scope.county).toBe(2); }); + + it('should execute the passed callback after having compiled the directive', function() { + scope.callbackCalled = false; + scope.gmapCallback = function(map) { + if (map) { + scope.callbackCalled = true; + } + }; + + $compile("
")(scope); + expect(scope.callbackCalled).toBeTruthy(); + }); }); describe('test infoWindow', function () {