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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With