Skip to content

Commit 3048de9

Browse files
Harm van der WerfHarm van der Werf
authored andcommitted
Wrapped "open" in promise
In case you want to open an info window and the template is not yet done loading it will wait for the template to be loaded first. I don't think it will happen often, but better be safe than sorry.
1 parent d06c530 commit 3048de9

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

directives/info-window.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
* it must have a container element with ng-non-bindable
7979
*/
8080
var template;
81-
$q(function(resolve) {
81+
var templatePromise = $q(function(resolve) {
8282
if (angular.isString(element)) {
8383
$templateRequest(element).then(function (requestedTemplate) {
8484
resolve(angular.element(requestedTemplate).wrap('<div>').parent());
@@ -98,21 +98,23 @@
9898
});
9999

100100
infoWindow.__open = function(map, scope, anchor) {
101-
$timeout(function() {
102-
anchor && (scope.anchor = anchor);
103-
var el = $compile(infoWindow.__template)(scope);
104-
infoWindow.setContent(el[0]);
105-
scope.$apply();
106-
if (anchor && anchor.getPosition) {
107-
infoWindow.open(map, anchor);
108-
} else if (anchor && anchor instanceof google.maps.LatLng) {
109-
infoWindow.open(map);
110-
infoWindow.setPosition(anchor);
111-
} else {
112-
infoWindow.open(map);
113-
}
114-
var infoWindowContainerEl = infoWindow.content.parentElement.parentElement.parentElement;
115-
infoWindowContainerEl.className = "ng-map-info-window";
101+
templatePromise.then(function() {
102+
$timeout(function() {
103+
anchor && (scope.anchor = anchor);
104+
var el = $compile(infoWindow.__template)(scope);
105+
infoWindow.setContent(el[0]);
106+
scope.$apply();
107+
if (anchor && anchor.getPosition) {
108+
infoWindow.open(map, anchor);
109+
} else if (anchor && anchor instanceof google.maps.LatLng) {
110+
infoWindow.open(map);
111+
infoWindow.setPosition(anchor);
112+
} else {
113+
infoWindow.open(map);
114+
}
115+
var infoWindowContainerEl = infoWindow.content.parentElement.parentElement.parentElement;
116+
infoWindowContainerEl.className = "ng-map-info-window";
117+
});
116118
});
117119
};
118120

0 commit comments

Comments
 (0)