lundi 2 mars 2015

Ember cli, how to initialize a service with a controller?

I have a service, called clock



//app/services/clock.js

export default Ember.Object.extend({
pulse: Ember.computed.oneWay('_seconds').readOnly(),
tick: function () {
var clock = this;
Ember.run.later(function () {
var seconds = clock.get('_seconds');
if (typeof seconds === 'number') {
clock.set('_seconds', seconds + (1/4));
}
}, 250);
}.observes('_seconds').on('init'),
_seconds: 0
});


I also have an initialzer where I want to register the clock service and then inject it into my "interval" route/controller.



// app/initializers/clock-service.js

import ClockService from 'app/services/clock';

export default {
name: 'ClockServiceInitializer',
initialize: function(container, application) {
container.register('clock:service', ClockService);
app.inject('controller:interval', 'clock', 'clock:service');
}
};




Aucun commentaire:

Enregistrer un commentaire