Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call method from other method within Ember Service

I'm just learning Ember.js and ran into a little snag. I have a Service where I want to call another method I have defined within the same object, like so:

export default Ember.Service.extend({
  myMethod: function() { ... },

  otherMethod: function() {
    this.myMethod(); // <---- this doesn't work
    this.get('myMethod')(); // <---- also doesn't work
    Ember.run.bind(this, this.myMethod)() // <---- no dice
  }
});

Is there any way to do this? I would greatly like to reuse code within my codebase.

Thanks.

like image 741
Jason Avatar asked Feb 20 '15 18:02

Jason


1 Answers

I'm guessing that you've already gone on from this point. But here's an ember-twiddle just in case that demonstrates how a service can reference its own methods. Like it was said in the comments, it's a javascript thing about this.

https://ember-twiddle.com/7caf29fe1df7f36e6e3e49578fc3aed3?openFiles=services.movie-service.js%2Ctemplates.components.movie-viewer.hbs

like image 50
shane Avatar answered Sep 21 '22 13:09

shane