angular-preloaded
This AngularJS plugin allows you to preload data for your application by putting it into a special script tag. This is especially great for non-SPAs that want to use AngularJS.
I am motivated by my previous attempts to preload data where I polluted
the global state (i.e. window
) and wrote services to pluck values off
of it. This approach fully integrates with the AngularJS life cycle.
Installing
bower install angular-preloaded
Using
You can preload any data that you need by wrapping JSON in a script tag
with type=text/preloaded
.
You can now access the preloaded data from anywhere in your application by
injecting $preloaded
.
angular;
NOTE: Your script tags must run before anything using $preloaded
, so
I suggest putting them in your document's head.