angular - Http provider Error Ionic 3 -
i'm getting error have no idea how fix. search solutions, didn't me.
it's make http request using ionic native http, both , post.
the error: it's i'm not setting http provider, in app.module.ts i'm importing it
error error: uncaught (in promise): error: no provider http! error: no provider http! @ injectionerror (vendor.js:1590) @ noprovidererror (vendor.js:1628) @ reflectiveinjector_._throwornull (vendor.js:3129) @ reflectiveinjector_._getbykeydefault (vendor.js:3168) @ reflectiveinjector_._getbykey (vendor.js:3100) @ reflectiveinjector_.get (vendor.js:2969) @ appmoduleinjector.get (ng:///appmodule/module.ngfactory.js:240) @ appmoduleinjector.getinternal (ng:///appmodule/module.ngfactory.js:365) @ appmoduleinjector.ngmoduleinjector.get (vendor.js:3936) @ resolvedep (vendor.js:11398) @ injectionerror (vendor.js:1590) @ noprovidererror (vendor.js:1628) @ reflectiveinjector_._throwornull (vendor.js:3129) @ reflectiveinjector_._getbykeydefault (vendor.js:3168) @ reflectiveinjector_._getbykey (vendor.js:3100) @ reflectiveinjector_.get (vendor.js:2969) @ appmoduleinjector.get (ng:///appmodule/module.ngfactory.js:240) @ appmoduleinjector.getinternal (ng:///appmodule/module.ngfactory.js:365) @ appmoduleinjector.ngmoduleinjector.get (vendor.js:3936) @ resolvedep (vendor.js:11398) @ c (polyfills.js:3) @ object.reject (polyfills.js:3) @ navcontrollerbase._fireerror (vendor.js:43003) @ navcontrollerbase._failed (vendor.js:42991) @ vendor.js:43046 @ t.invoke (polyfills.js:3) @ object.oninvoke (vendor.js:4508) @ t.invoke (polyfills.js:3) @ r.run (polyfills.js:3) @ polyfills.js:3
the code:
app.module.ts
import { browsermodule } '@angular/platform-browser'; import { errorhandler, ngmodule } '@angular/core'; import { httpmodule } '@angular/http'; import { ionicapp, ionicerrorhandler, ionicmodule } 'ionic-angular'; import { myapp } './app.component'; import { homepage } '../pages/home/home'; import { listpage } '../pages/list/list'; import { cadastropage } '../pages/cadastro/cadastro'; import { apiservice } '../services/api.service'; import { statusbar } '@ionic-native/status-bar'; import { splashscreen } '@ionic-native/splash-screen'; @ngmodule({ declarations: [ myapp, homepage, listpage, cadastropage ], imports: [ browsermodule, httpmodule, ionicmodule.forroot(myapp) ], bootstrap: [ionicapp], entrycomponents: [ myapp, homepage, listpage, cadastropage ], providers: [ apiservice, statusbar, splashscreen, {provide: errorhandler, useclass: ionicerrorhandler} ] }) export class appmodule {}
api.service.ts
import { injectable } '@angular/core'; import { http } '@ionic-native/http'; @injectable() export class apiservice { constructor (private http: http) { } private apiurl = '<valid_url>'; get() { // ok http request here! } }
packaje.json
{ "name": "app", "version": "0.0.1", "author": "ionic framework", "homepage": "http://ionicframework.com/", "private": true, "scripts": { "clean": "ionic-app-scripts clean", "build": "ionic-app-scripts build", "lint": "ionic-app-scripts lint", "ionic:build": "ionic-app-scripts build", "ionic:serve": "ionic-app-scripts serve" }, "dependencies": { "@angular/common": "4.1.3", "@angular/compiler": "4.1.3", "@angular/compiler-cli": "4.1.3", "@angular/core": "4.1.3", "@angular/forms": "4.1.3", "@angular/http": "4.1.3", "@angular/platform-browser": "4.1.3", "@angular/platform-browser-dynamic": "4.1.3", "@ionic-native/core": "3.12.1", "@ionic-native/http": "^4.1.0", "@ionic-native/splash-screen": "3.12.1", "@ionic-native/status-bar": "3.12.1", "@ionic/storage": "2.0.1", "cordova-android": "^6.2.3", "cordova-plugin-console": "1.0.5", "cordova-plugin-device": "1.1.4", "cordova-plugin-splashscreen": "~4.0.1", "cordova-plugin-statusbar": "2.2.2", "cordova-plugin-whitelist": "1.3.1", "ionic-angular": "3.5.3", "ionic-plugin-keyboard": "~2.2.1", "ionicons": "3.0.0", "rxjs": "5.4.0", "sw-toolbox": "3.6.0", "zone.js": "0.8.12" }, "devdependencies": { "@ionic/app-scripts": "2.0.2", "@ionic/cli-plugin-cordova": "1.5.0", "@ionic/cli-plugin-ionic-angular": "1.4.0", "ionic": "3.6.0", "typescript": "2.3.4" }, "description": "an ionic project", "cordova": { "plugins": { "cordova-plugin-console": {}, "cordova-plugin-device": {}, "cordova-plugin-splashscreen": {}, "cordova-plugin-statusbar": {}, "cordova-plugin-whitelist": {}, "ionic-plugin-keyboard": {} }, "platforms": [ "android" ] } }
in apiservice this
import { injectable } '@angular/core'; import { http } '@angular/http'; @injectable() export class apiservice { constructor (private http: http) { } private apiurl = '<valid_url>'; get() { // ok http request here! } }
your error comes line
import { http } '@ionic-native/http';
but imported module @angular/http
!
Comments
Post a Comment