I want to use static HTTP client service for some reasons. I tried it like the following but I got an error. Is creating static the service possible?
static service:
import { Http, URLSearchParams, Headers } from '@angular/http';
export class ExampleService {
static postSendTransaction(data, callback) {
Http.post('https://xxxxxxxx', JSON.stringify(data), { // I got error here
headers: new Headers({ 'Content-Type': 'application/json' })
}).subscribe(
response => {
callback({data: response.json(), error: null});
},
error => {
callback({data: null, error: error.statusText});
}
);
}
}
example call:
ExampleService.postSendTransaction(this.data, postSendTransactionCallback);
I got this error:
Property 'post' does not exist on type 'typeof Http'.
Httpclass is not designed to be used as a static object. You need to inject it into the constructor and use it the way it was designed.