I trying to use: HTTP https://beta.ionicframework.com/docs/native/http
In the service, I import and use HTTP, but when I run, it responses NullInjectorError: No provider for HTTP!
I see that I missed the import into de Module app.module.ts
but I don’t know which module I need to import. I try import import { HttpModule } from '@angular/http';
but doesn’t work…
PD. also, should not be specified inside this documentation?
- Service:
// app/auth.service.ts
import { HTTP } from '@ionic-native/http/ngx';
...
export class AuthService {
constructor( private http: HTTP ) { }
public login(credentials) {
...
this.http.get(url, {}, {})
.then(data => {
console.log('data:');
console.log(data.status);
console.log(data.data); // data received by server
console.log(data.headers);
})
.catch(error => {
console.log('error');
console.log(error.status);
console.log(error.error); // error message as string
console.log(error.headers);
Observable.throw("Error http:" + error.error);
});
...
- Modules
// app/app.module.ts
import { HttpModule } from '@angular/http';
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [
BrowserModule,
IonicModule.forRoot(),
AppRoutingModule,
HttpModule
],
...