Getting type error while calling a function in ember service from ember route

Uncaught TypeError: this.jobs_service.stopJob is not a function at n.stopJob (ui.js:6) at ui.js:6 at Array.forEach () at n.stopQuery (ui.js:6) at u.T [as triggerEvent] (vendor.js:13) at Object.l [as trigger] (vendor.js:18) at u.trigger (vendor.js:18) at n.send (vendor.js:13) at n.send (vendor.js:14) at n.triggerAction (vendor.js:14)

Following is my service function: export default Ember.Service.extend({ stopJob : function(jobId) { //stopJob (jobId) { // this.setCurrentQueryAsCancelled(); return new Ember.RSVP.Promise((resolve, reject) => { let job = this.get(‘store’).peekRecord(‘job’, jobId); if(job) { job.destroyRecord(); } else { this.get(‘store’).findRecord(‘job’, jobId, { reload: true }) .then(job => { job.deleteRecord(); return resolve(""); }).catch(function (response) { return resolve(""); }); } }); }, }

and following is the code in route from where the function is called: stopJob(jobId) { var self = this; self.jobs_service.stopJob(jobId) .then(data => { //this.get(‘controller’).set(‘isJobCancelled’, true); console.log(“Job " + jobId + " stopped”); }).catch(function (response) { //self.get(‘controller’).set(‘isJobCancelled’, true); console.log(“Job " + jobId + " stopped”); }); },

What am I doing wrong here?Preformatted text

Hey @sonalg, It’s really hard to make sense of what’s going on here. Could you edit your post with some code formatting? (the </> button in the toolbar)

Reading through the route code I’d say you need to write this.get(‘jobs_service’).stopJob(…).

Also since your using fat arrows ( => ) in the function you don’t need to pass this as self. You can just use this.