1
votes

I'm working on my own ember addon and I'm trying to use ajax request as follows (component):

ajax: Ember.inject.service(),

ajaxRequest(method, href, type, json,callback) {
  let ajax = this.get('ajax');
  let promise = ajax.request(href, {
    method: 'POST',
    data:  json
  });
  promise.then(() => {
   callback();
  }).catch((e) => {
   console.log(e);
  });
},

But i get :

ember.debug.js:2307 Uncaught Error: Attempting to inject an unknown injection: 'service:api'

DEBUG: 
-------------------------------
Ember      : 2.9.1
Ember Data : 2.10.0
jQuery     : 3.1.1
-------------------------------
1
Did you install ember-ajax addon in your project. do you have entry for ember-ajax in package.json file - Ember Freak
i installed - ember install ember-ajax in my package.json in devDependencies --> "ember-ajax": "2.5.3", – - Fesco
try the below step rm -rf node_modules bower_components tmp and npm install && bower install for clean fresh installation dependancies - Ember Freak
i found this step in the web but is not working. is it necessary to say that i#m working on my own addon? - Fesco
check this link. you need to specify it in dependencies not in devDependencies - Ember Freak

1 Answers

1
votes

If your addon depends on another addon, install it as a dependency in your package.json:

"dependencies": {
  "ember-ajax": "^0.7.1"
}

Reference