İonic 3 rest API Web Service Provider
Http Get, Http Post
-
Create Provider WebService
-
Import WebService Provider and HttpClientModule "app/app.module.ts"
-
Add "WebServiceProvider" providers tag and Add HttpClientModule add imports tag
-
Import WebService Provider your page and add public or private your constructor tag
-
Example:
import { HttpClientModule } from '@angular/common/http'; import { WebServiceProvider } from '../providers/web-service/web-service'; ... imports: [ ... BrowserModule, HttpClientModule, IonicModule.forRoot(MyApp) ], ... providers: [ ... {provide: ErrorHandler, useClass: IonicErrorHandler}, WebServiceProvider, ]
import { WebServiceProvider } from './../../providers/web-service/web-service'; constructor(public navCtrl: NavController, public navParams: NavParams,private ws: WebServiceProvider) {} ionViewDidLoad() { let param = [ {"key":"param1", value:"value1"}, {"key":"param2", value:"value2"}, ] this.ws.getdata('your_page.php', param).then( data =>{ console.log(data); } }).catch( error => { this.ws.erroralert(error); }) }
import { WebServiceProvider } from './../../providers/web-service/web-service'; constructor(public navCtrl: NavController, public navParams: NavParams,private ws: WebServiceProvider) {} ionViewDidLoad() { let param = [ {"key":"param1", value:"value1"}, {"key":"param2", value:"value2"}, ] this.ws.postdata("your_post_url.php", param).then( data => { console.log(data); }).catch( error =>{ this.ws.erroralert(error); }) }