The dependency injection pattern is used to declare and instantiate classes of objects and handle dependencies between them. In Ember, we can take objects or services and inject them into routes, controllers, or components.
In this recipe, we'll take a logger object and inject it into our controllers using dependency injection.
In a new application, install the
moment
library and create a newinitializer
:$ bower install moment –save $ ember g initializer application
This will install the Bower Moment.js library. We'll use this for our custom logger.
Import the Moment library to the Ember project:
// ember-cli-build.js /*jshint node:true*/ /* global require, module */ var EmberApp = require('ember-cli/lib/broccoli/ember-app'); module.exports = function(defaults) { var app = new EmberApp(defaults, { // Add options here }); app.import('bower_components/moment/min/moment.min.js'); return app.toTree(); };
The
app.import
statement...