Skip to content

Instantly share code, notes, and snippets.

View renanfranca's full-sized avatar
😄

Renan Franca renanfranca

😄
View GitHub Profile
@renanfranca
renanfranca / LazyLoad.js
Created October 20, 2015 14:34 — forked from neilsoult/LazyLoad.js
LazyLoad directive for loading external javascript for AngularJs. In this example, I use google maps' API as the external library being loaded
angular.module('testApp', []).
directive('lazyLoad', ['$window', '$q', function ($window, $q) {
function load_script() {
var s = document.createElement('script'); // use global document since Angular's $document is weak
s.src = 'https://maps.googleapis.com/maps/api/js?sensor=false&callback=initialize';
document.body.appendChild(s);
}
function lazyLoadApi(key) {
var deferred = $q.defer();
$window.initialize = function () {