Working with application initializers

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.

How to do it...

  1. 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.

  2. 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.

  3. Run ember server and you should see an alert ...

Get Ember.js Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.