Calling a method from another method in the Ember service

I just learn Ember.js and come across a little grasp. I have a service where I want to call another method that I defined inside the same object:

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 really like to reuse the code in my code base.

Thanks.

+7
javascript
source share
1 answer

I assume you already did this. But here, an inflatable game just in case demonstrates how a service can refer to its own methods. As said in the comments, this is a javascript thing about this .

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

+2
source share

All Articles