mercredi 20 avril 2016

Emberjs Service is undefined after loading

I would like to inject 'eventBus' service into my component but after injection service is undefined. I am using ember 2 and I was following this tutorial (http://ift.tt/22OLrwX) but it doesn't work for me.

services/event-bus.js

import Ember from 'ember';

export default Ember.Service.extend(Ember.Evented, {
  init() {
    this._super(...arguments);
  },
  publish: function() {
    return this.trigger.apply(this, arguments);
  },
  subscribe: function() {
    this.on.apply(this, arguments);
  },
  unsubscribe: function() {
    this.off.apply(this, arguments);
  }
});

components/rooms-list.js

import Ember from 'ember';

const RoomList = Ember.Component.extend({
  eventBus: Ember.inject.service(),
  didReceiveAttrs () {
    this.set('currentRoomId', this.get('params')[1].id);
  },
  model: Ember.computed('params.[]', function(){
    return this.get('params')[0];
  }),
  actions: {
    onRoomClicked(roomId) {
      this.get('eventBus').publish(); //Uncaught TypeError: Cannot read property 'publish' of undefined
      this.set('currentRoomId', roomId);
    },
    deleteRoom(room) {
      console.log('delete room', room);
    }
  }
});

RoomList.reopenClass({
  positionalParams: 'params'
});

export default RoomList;




Aucun commentaire:

Enregistrer un commentaire