Here’s a simple example on how to setup a simple JSON file as a config file for your directive/module:
What happens here is as follows:
- The directive loads.
- It asks for the config from the service (or it could do it on its own).
$http.getreturns a promise, and the
inithappens only after we get the data.
- In this example, the config holds only our Bing map API key. It could also hold urls, delimiters and any other piece of data you would like to use before initializing your directive.
You could expand this code for many other use cases. For instance, setup a default config in case the
get has failed for some reason.