← Back to team overview

dhis2-devs-core team mailing list archive

D2 app init

 

Hi everyone

Just wanted to quickly share to link [1]. It shows an example off how to
run one or more async request before your main module is initialized. This
is very useful in d2 app development, since you probably want to get
/api/system/info and /api/me etc and provide them as constants in your app.

A simple example would be:
(function() {
    angular.injector(['ng']).get('$http').get('system.json').then(
        function( response ) {
            angular.module('config', []).constant('CONFIG', response.data);
            angular.element(document.body).ready(function() {
                angular.bootstrap(document.body, ['MyApp']);
            });
        }
    );
})();

Of course, if you have multiple links you want to get, you probably want to
use the injector to also get $q service etc, to properly send out async
request and pull them back together before doing module init.

At some point, we should probably provide our own d2.init module, which
would allow this kind of bootstrapping (also providing Me service etc).

[1]
http://stackoverflow.com/questions/16286605/initialize-angularjs-service-with-asynchronous-data

--
Morten

Follow ups