I'm playing with the Aurelia intro tutorial and changing it to make a rest call from a custom class. In my class I'm getting an 'http is undefined' error with my method calls, so it appears that Aurelia services aren't being injected. Does injecting work if Aurelia isn't loading the class module?
home.js:
import 'bootstrap/css/bootstrap.min.css!';
import 'bootstrap/css/bootstrap-theme.min.css!';
import 'styles/style.css!'
import 'bootstrap';
import {Search} from '../lib/search.js';
export class Home {
heading = 'Welcome to Aurelia!';
firstName = 'John';
lastName = 'Doe';
activate() {
}
get fullName() {
return `${this.firstName} ${this.lastName}`;
}
submit() {
var s = new Search();
s.fetch()
.then(results => this.results = results);
}
}
search.js:
import {inject} from 'aurelia-framework';
import {HttpClient} from 'aurelia-fetch-client';
import 'fetch';
@inject(HttpClient)
export class Search {
constructor(http) {
// constructor is called but http is undefined
http.configure(config => {
config
.useStandardConfiguration();
});
this.http = http;
}
fetch() {
// ERROR OCCURS HERE
return this.http.fetch('find')
.then(response => response.json());
}
}
Error:
TypeError: http is undefined