angular-piwik
angular-piwik copied to clipboard
Execution environment specific config
Hi everybody,
Spending some hours without finding a working solution I tried to load the js-url, tracker-url and site-id configuration from my REST API during custom Angular bootstrapping, then make it available to my modules via the $scope in order to be able to pass them to the ngp-piwik directive within the html...
The idea behind: Being able to have different js-url, tracker-url and site-id per environment.
Example:
<pre>{{environmentConfig[0].value}}</pre>
<ngp-piwik ngp-set-js-url="{{environmentConfig[1].value}}"
ngp-set-tracker-url="{{environmentConfig[2].value}}" ngp-set-site-id="{{environmentConfig[3].value}}"></ngp-piwik>
More in detail I am using a deferred bootstrapper:
/**
* The deferred boot strapper loading config from the back-end before bootstrapping
* the app.
*/
window.deferredBootstrapper.bootstrap({
element: window.document.body,
module: 'myApp',
resolve: {
environmentConfig: ['$http', function ($http) {
return $http.get('/rest/skin/environmentConfig');
}]
},
onError: function (error) {
console.error("Failed to bootstrap, error: " + error)
}
});
And while doing the following I can also see in the console output that the JSON config has been loaded successfully:
angular.module('bepraxis')
.config(function (environmentConfig) {
console.log('APP_CONFIG is: ' + JSON.stringify(environmentConfig));
})
The problem I am running into is the asynchronous part during boot strapping or lets say the config is not available at the moment when the ngp-piwik directive is being injected...
So my question: Has anyone out in the wild faced a similar situation where the analytics server url and site ID could not be hard coded but instead per environment configuration was required?
Thanks a lot in advance for your valuable support.
Best, Simon