Last active
August 29, 2015 14:16
-
-
Save toamitkumar/7e138e85d53bab9014d2 to your computer and use it in GitHub Desktop.
angular lazy load modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('xyzApp', [ | |
'....' | |
'uiGmapgoogle-maps', | |
'ui.bootstrap', | |
'duScroll', | |
'base64', | |
'angularModalService', | |
'oc.lazyLoad' | |
]) | |
.config(['uiGmapGoogleMapApiProvider', function(uiGmapGoogleMapApiProvider) { | |
uiGmapGoogleMapApiProvider.configure({ | |
client: 'gme-xyz', | |
v: '3.17' | |
}); | |
}]); | |
// Routes | |
var routes = { | |
'/': { | |
templateUrl: 'views/home.html', | |
controller: 'MainCtrl' | |
}, | |
'/google-map': { | |
templateUrl: 'views/google-map.html', | |
controller: 'GoogleCntrl', | |
resolve: { | |
lazyGmaps: ['$q', '$ocLazyLoad', '$window', 'Features', | |
function($q, $ocLazyLoad, $window, Features) { | |
if (typeof google !== 'undefined' && angular.isDefined(google.maps)) return false; | |
var deferred = $q.defer(); | |
$window.onGoogleMapsReadySearchresultsCtrl = function() { | |
delete($window.onGoogleMapsReadySearchresultsCtrl); | |
deferred.resolve(); | |
}; | |
$ocLazyLoad | |
.load('https://maps.googleapis.com/maps/api/js?client=gme-thomascookukgroup&v=3.17&callback=onGoogleMapsReadySearchresultsCtrl') | |
.catch(function() { | |
if (!angular.isDefined($window.onGoogleMapsReadySearchresultsCtrl)) return; | |
$window.onGoogleMapsReadySearchresultsCtrl(); | |
}); | |
return deferred.promise; | |
} | |
}] | |
} | |
} | |
}; | |
Object.keys(routes).forEach(function (route){ | |
$routeProvider.when(route, routes[route]); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment