Last active
August 29, 2015 14:03
-
-
Save bitwit/b8d1a4fa4806d9acefc4 to your computer and use it in GitHub Desktop.
Angular data preloading
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('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