Application initializers can be used to configure your application as it boots. It's the primary place to set up dependency injections in your application.
In this example, we'll examine when an application initializer is run.
In a new application, create
initializer
:$ ember g initializer application
This will create a new application
initializer
. This will be run as soon as the application boots.Add an alert box to the initializer:
// app/initializers/application.js export function initialize( application ) { alert('loading application'); } export default { name: 'application', initialize };
This will load an
alert
box as soon as the application loads.Run
ember server
and you should see an alert box displayed before the application is loaded:Nothing else has loaded in the application before this alert box is shown.
If needed, we can also
register
orinject
services in the initializer. It may look as follows:// app/initializer...