EmberJS – Initializers

Initializer

Initializer are used to configure an application as it boots. Initializers contain two types −

  • Application Initializers − An application initializer runs as your application boots and configures the dependency injection in your application.
  • A Application Instance Initializers − An application instance initializers run when an application instance is loaded and configures the initial state of an application.

Application Initializer

The Application initializers can be created by using the following command −

ember generate initializer initializer-name

When you create an initializer, it will display the following code format −

export function initialize(/* application */) {
   //application.inject('route', 'foo', 'service:foo');
}

export default {
   //'logger' is an application initializer name
   name: 'logger',
   initialize
}; 

Application Instance Initializers

An instance initializer for an application can be created by using the following command −

ember generate instance-initializer instance-initializer-name

When you run the above command, it will display the the following code structure −

export function initialize(/* appInstance */) {
   // appInstance.inject('route', 'foo', 'service:foo');
}

export default {
   //'logger' is an application instance initializer name
   name: 'logger',
   initialize
};

For more about these two initializers along with an example, see this link.

Previous Page:-Click Here

Leave a Reply