Skip to content

Commit da415a2

Browse files
committed
Merge pull request allenhwkim#565 from aitboudad/map-lazy-load
[map-lazy-load] keep element content for each calls.
2 parents fc79549 + 3cdfde0 commit da415a2

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

directives/map-lazy-load.js

Lines changed: 18 additions & 10 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[elements.length],
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

@@ -69,7 +77,7 @@
6977
var compileFunc = function(tElement, tAttrs) {
7078

7179
(!tAttrs.mapLazyLoad) && console.error('requires src with map-lazy-load');
72-
savedHtml = tElement.html();
80+
savedHtml.push(tElement.html());
7381
src = tAttrs.mapLazyLoad;
7482

7583
/**

0 commit comments

Comments
 (0)