Skip to content

Instantly share code, notes, and snippets.

@bitwit
Last active August 29, 2015 14:03
Show Gist options
  • Save bitwit/b8d1a4fa4806d9acefc4 to your computer and use it in GitHub Desktop.
Save bitwit/b8d1a4fa4806d9acefc4 to your computer and use it in GitHub Desktop.
Angular data preloading
angular.module('appModule')
//app initialization
.constant('MY_CONFIG', {})
.config(['MY_CONFIG', function(MY_CONFIG){
var scripts = document.getElementsByTagName('script');
for (var i = 0; i < scripts.length; i++) {
var script = scripts[i];
if(script.type === 'text/preloaded'){
var data = JSON.parse(script.innerHTML);
angular.extend(MY_CONFIG, data);
}
}
}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment