0
votes

I need to access an ember controllers context from within a regular object. Currently I am saving a reference to the controller context in the init() method that seems a little crappy.

let self = this //saving the context here
export default Ember.controller.extend({

  init() {
    this._super(...arguments);
    self = this;
  },

  settings: {
     crud: {
        read: {
          enabled: true,
          default() {
            return self.get('blah.blah'); //Need to access the controller context
          }
        }
     }
  }

});

So I need access to the controller self.get('blah.blah'). Is there a better way to do this?

1

1 Answers

0
votes

Use a computed property closure

export default Ember.controller.extend({

  settings: Ember.computed(function() {
     const controller = this;

     return {
       crud: {
        read: {
          enabled: true,
          defaults() {
            return controller.get('blah.blah');
          }
         }
       }
     };
  })

});

Accessing object

this.get('settings').crud.read.defaults(); // "blah.blah"