dimanche 26 avril 2015

Can't get Injected Ember Service from Ember Controller - But works on models & adapters

I'm running into an issue with an Ember CLI project where I can't get an injected ember service from a controller action function.

The really strange thing is that this totally works on my models and custom adapters:

the controller:

export default Ember.Controller.extend({
  node: Ember.inject.service(),

  azureStorage: Ember.computed.alias('node.azureStorage'),

  actions: {

    myAction: function () {
      // this returns null
      var x = this.get('azureStorage');
    }
  }
});

// The service code (azureStorage and fs are NOT null)

if (window.requireNode) {
    azureStorage = window.requireNode('azure-storage');
    fs = window.requireNode('fs');
}
export default Ember.Service.extend({
    azureStorage: azureStorage,
    fs: fs,
    getActiveAccount: function (store) {
        return new Ember.RSVP.Promise(function (resolve, reject) {
            var accounts = store.all('account'),
                length = accounts.get('length'),
                i = 0;
            accounts.forEach(function (account) {
                if (account.get('active') === true) {
                    return Ember.run(null, resolve, account);
                }
                i += 1;
                if (i >= length) {
                    return Ember.run(null, reject, 'could not find any active accounts');
                }
            });
        });
    }
});



// the controller test code

var controller = this.subject();
controller.send('myAction');

I would have expected this to return the service and the azureStorage object. On my models & adapters the same pattern works just fine:

export default DS.Adapter.extend({
    serializer: serializer.create(),
    node: Ember.inject.service(),
    azureStorage: Ember.computed.alias('node.azureStorage'),
    findQuery: function () {
      // this returns the value correctly
      var x = this.get('azureStorage');
    }
});

Any reason this would work on models & adapters but NOT on a controller?




Aucun commentaire:

Enregistrer un commentaire