Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4870

Error: Assertion Failed: Attempting to inject an unknown injection: 'service:ajax'

$
0
0

am trying to make an ajax request following an old tutorial :

ajax: service(),
async authenticate(username, password) {
    let response = await this.ajax.post('/token', {
      headers: {
        'Accept': 'application/vnd.api+json',
        'Content-Type': 'application/vnd.api+json',
      },
      data: JSON.stringify({
username,
password })
})
let { user_email: userEmail, token } = response; return { userEmail, token };
}```

what am doing is : 
```import { inject as service } from '@ember/service';
@service ajax;
async authenticate(email, password){
    let response = await this.ajax.post('tokens', {
      headers: {
        'Accept': 'application/vnd.api+json',
        'Content-Type': 'application/vnd.api+json'
      },
      data: JSON.stringify({
        email,
        password
      })
    })
    let {user_email: userEmail, token} = response;
    return {UserEmail, token};
  }```
and what i get is that 
Error: Assertion Failed: Attempting to inject an unknown injection: 'service:ajax'

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 4870

Trending Articles