Repository: angular/angular.js

Issue #4010: A universal resolve object on RouteConfigs?
Created: 2013-09-15T03:33:41Z
This would mostly be sugar, but can possibly relieve an awful lot of repetition, while also permitting us to think in terms of 'route-specific data' and 'app-wide-data'.
Assume that we're making as much of the app data-driven as possible, including things like navigation contents. There is essential async data that has to load out before any route loads, in the event that the user deep-links straight into the middle of the app. So, we can't just put that essential data onto "/" and assume it'll be available when needed elsewhere.
The answer? resolve: to the rescue. But, if you have an app with 30 routes, and you need a promise that's resolved before any of them load, you're going to repeat your everywhere promise 30 times in the routeConfigs, and then your route-specific onlyHere promises along with it. It works, of course, but all that redundancy just... looks wrong. It's not the Angular Way.
Suggestion: some form of configuration option that specifies a resolve object that is applicable on all routes.
(The only clean alternative I've been able to suss out so far: use manual bootstrap and resolve that universal data source before bootstrap, then inject as a constant and reference in a service.)

Duplicate issue #14170: Initializing application settings from the server side
Created: 2016-03-03T14:21:43Z
There is a need for angular application to load settings from the server when initializing, before it's bootstrapped. For example, application needs to know location of the token service, api service or anything else. This configuration is stored on the server in a file separate from the minified source code to simplify configuration changes.

What is the current behavior?
It would be natural to put this initalization code into Config or Run application methods. The problem is that any ajax request is asynchronous and there is no way to halt bootstraping.

As a workaround(example below) a manual call via XHR is made to the server and bootstrapping doesn't begin until:
a) Dom is loaded.
b) Server settings are loaded.
The code looks cumbersome. Additionally, there's no way to inject custom variable (server settings) into config, so higher scope variable is used to work around the issue.
CodePen: http://codepen.io/akoltsov/pen/PNqxVo
Pseudo code:
/**** START ****/
var SERVERSETTINGS = {}; // notice high scope
var app = angular.module('X');

var xhr = new XmlHttpRequest();
xhr.onload = function() {
  IsConfigLoaded = true;
  app.config(function(ConfigProvider) {
    // apply loaded settings in the app.
    ConfigProvider.Configure(SERVERSETTINGS); // extends default settings
    bootstrap();
  }
};
xhr.send();

angular.element(document).ready(function () {
  IsDomLoaded = true;
  bootstrap();
});

bootstrap() {
  if (IsDomLoaded and IsConfigLoaded) {
    angular.bootstrap(document, app.name);
  }
}

/**** END ****/


What is the desired behavior?
Is there a simpler way or we need a way to delay running of angular application until it's ready.
What is the motivation / use case for changing the behavior?
Ability to configure application from the server.
Which version of Angular, and which browser and OS does this issue affect? Did this work in previous
versions of Angular? Please also test with the latest stable and snapshot versions.
Any 1.x version.

Closing comment (2016-03-04T08:35:09Z): This is a dupe of #5854
and similar to
#4010
#4003
There are currently no plans to implement this, mainly because the workarounds for this specific problem aren't too horrendous.