I am trying to manually bootstrap AngularJS after receiving data from the server.
bootstrap.js:
var initInjector = angular.injector(['ng']);
var $http = initInjector.get('$http');
var maindata;
function bootstrapAngular() {
angular.element(document).ready(function() {
angular.bootstrap(document, ['app']);
});
}
function getMainData() {
return maindata;
}
$http
.get('/data')
.then(function (response) {
maindata = response.data;
bootstrapAngular();
}, function (error) {
console.log(error);
});
I need to use the maindata or getMaindata() in the app after it is bootstrapped. Therefore, I cannot have javascript closer (function(){})(); on bootstrap.js file to keep everything private, so that the function & variable is accessible to the other part of the app.
Is it possible to make everything private but still accessible to the other part of the app?
New Dev's answer solve my problem. Or, you have better suggestion how to write it?