Skip to content

Commit 9333d52

Browse files
committed
[map-lazy-load] keep element content for each calls.
1 parent fc79549 commit 9333d52

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

directives/map-lazy-load.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,28 @@
3636
/* global window, document */
3737
(function() {
3838
'use strict';
39-
var $timeout, $compile, src, savedHtml;
39+
var $timeout, $compile, src, savedHtml, elements = [];
4040

4141
var preLinkFunc = function(scope, element, attrs) {
4242
var mapsUrl = attrs.mapLazyLoadParams || attrs.mapLazyLoad;
4343

44-
window.lazyLoadCallback = function() {
45-
console.log('Google maps script loaded:', mapsUrl);
46-
$timeout(function() { /* give some time to load */
47-
element.html(savedHtml);
48-
$compile(element.contents())(scope);
49-
}, 100);
50-
};
51-
5244
if(window.google === undefined || window.google.maps === undefined) {
45+
elements.push({
46+
scope: scope,
47+
element: element,
48+
savedHtml: savedHtml,
49+
});
50+
51+
window.lazyLoadCallback = function() {
52+
console.log('Google maps script loaded:', mapsUrl);
53+
$timeout(function() { /* give some time to load */
54+
elements.forEach(function(elm) {
55+
elm.element.html(elm.savedHtml);
56+
$compile(elm.element.contents())(elm.scope);
57+
});
58+
}, 100);
59+
};
60+
5361
var scriptEl = document.createElement('script');
5462
console.log('Prelinking script loaded,' + src);
5563

0 commit comments

Comments
 (0)