I am currently developing an Angular application that is designed to load a JSON object from the server on page load, either freshly or if it doesn't already exist. I'm wondering how one could use a service or factory to check for the presence of this JSON object on the page. If it is found, the app should use that data and inject it into the controller. However, if the JSON object is not present, the app should make a request to the server to retrieve it.
For example:
var data = {item1: foo, item2: bar, item3: baz}
If this data exists on page load, Angular will utilize the 'data' variable as the foundation to construct the model. But if the data is not available, the app would then contact the server to obtain the same object and use that information instead.
While I am still relatively new to Angular, I have acquired enough knowledge to understand how to perform AJAX requests and properly bind returned data. In this specific scenario, my main inquiry is regarding the appropriate method to verify the existence of data in order to determine whether a call to the server is required during app execution.