How to setup $.params in ionic v1 to ionic v2


#1

i have code in ionic v1

appServices.factory('apiPesawatService', function($http) {
    var baseUrl = 'http://api.com/getdata.php?';
    return {
        getAll: function(data){
			//console.log(JSON.stringify(baseUrl+ $.param(data)));
            return $http.get(baseUrl+ $.param(data));
            //return $http.jsonp(baseUrl, {jsonpCallbackParam: 'callback'});
        },
    };
    
});

and the problem is how to make $ .param (data) in ionic v1 work in ionic v2 :persevere::persevere:


#2

The frameworks are so different that thinking of how to make AngularJS construct X work in modern Angular is not very useful. The modern Angular HttpClient is documented here, I would just read that and rewrite your service from scratch.


#3

of course i know it but after i try and not insert the $ .params i get is [Object Object]
provider service.ts

import { Http, Response ,Headers, RequestOptions } from '@angular/http';
import { HttpClientModule } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';

let baseUrl='http://api.blabla.com/getdata.php?';
@Injectable()
export class ApiPesawatService {

  constructor(public http: Http) {
    console.log('Hello ApiPesawatServiceProvider Provider');
  }
  getAll(data:any) {
    return new Promise((resolve, reject) => {
    console.log(JSON.stringify(baseUrl+ data));
          return this.http.get(baseUrl+ data)
          .subscribe(res => {
            resolve(res.json());
          }, (err) => {
            reject(err);
          });
        });
          //return $http.jsonp(baseUrl, {jsonpCallbackParam: 'callback'});
      }

}

etiket.ts


  searchEtiket(etiket, $event){
    let loadingPopup = this.loadingCtrl.create({
      content: 'Loading...'
    });
		loadingPopup.present();
    this.storage.get('blabla_m').then((prof) => {
      this.datauser = JSON.parse(prof);
		//this.flightdate=new Date();
    var load = 0;
    this.requestData = {
      flightto: this.flightto,
      flightfrom: this.flightfrom,
      flightdate: this.flightdate,
      flightdateback: '',
      flightpp: 0,
      flightadult: this.flightadult,
      flightchild: this.flightchild,
      flightinfant: this.flightinfant,
      member: 'blabla',
      method: 'cekflightairlines',
      airlines: 'citilink',
      //id: $scope.datauser[0].id
    };
    console.log(this.requestData);
    this.ApiPesawatService.getAll(this.requestData).then((result) => {
      this.data = result;
      if(this.data.status == 100 && this.data.data_penerbangan){
        this.data.citilink.pergi.forEach(function(value , index){
          var price = 0;
          var hargapromo = '';
          var price2 = 0;
          var hargaekonomi = '';
          var price3 = 0;
          var hargabisnis = '';
          var maskapai=[];
          if(value.harga.promo !='undefined' && value.harga.promo != null){
            if(value.harga.promo.usia.dewasa !='undefined' && value.harga.promo.usia.dewasa != null){
              price = value.harga.promo.usia.dewasa.total;
              hargapromo = value.harga.promo.data;
            }else{
              price =0;
              hargapromo = '';
            }
          }else{
            price =0;
            hargapromo = '';
          }

          if(value.harga.ekonomi !='undefined' && value.harga.ekonomi != null){
            //id = value2.harga.ekonomi.id;
            if(value.harga.ekonomi.usia.dewasa !='undefined' && value.harga.ekonomi.usia.dewasa != null){
              price2 = value.harga.ekonomi.usia.dewasa.total;
              hargaekonomi = value.harga.ekonomi.data;
            }else{
              price2 =0;
              hargaekonomi = '';
            }
          }else{
            price2 =0;
            hargaekonomi = '';
          }

          if(value.harga.bisnis !='undefined' && value.harga.bisnis != null){
            //id = value2.harga.bisnis.id;
            if(value.harga.bisnis.usia.dewasa !='undefined' && value.harga.bisnis.usia.dewasa != null){
              price3 = value.harga.bisnis.usia.dewasa.total;
              hargabisnis = value.harga.bisnis.data;
            }else{
              price3 =0;
              hargabisnis = '';
            }
          }else{
            price3 =0;
            hargabisnis = '';
          }
          
								this.data.each( value.pesawat, function( key2, value2 ) {
									
									var nm = '';						
									if (value2.kode.search("IW") >= 0){
										nm = 'wings';
									}else if(value2.kode.search("ID") >= 0){
										nm = 'batik';
									}else if(value2.kode.search("IN") >= 0){
										nm = 'nam';
									}else if(value2.kode.search("KD") >= 0){
										nm = 'kalstar';
									}else{
										nm = 'citilink';
									}
									var datamaskapai = {
										nama:nm,
										kode:value2.kode,
										kode_asal:value2.kode_asal,
										kode_tujuan:value2.kode_tujuan,
										waktu_asal:value2.waktu_asal,
										waktu_tujuan:value2.waktu_tujuan,
									};
									maskapai.push(datamaskapai);
                });
                
								var datas = {
									maskapai : maskapai, 
									//penerbangan : penerbangan, 
									promo : price, 
									datapromo : hargapromo, 
									ekonomi : price2, 
									dataekonomi : hargaekonomi, 
									bisnis : price3, 
									databisnis : hargabisnis, 
								};
								this.pesawatList.push(datas);
        });
      }
    }, (err) => {
      if (err.error && err.error.length >= 1) {
        loadingPopup.dismiss();
          let alert = this.alertCtrl.create({
            subTitle: 'Maaf!!',
            message: err.error[0].responseMessage,
            buttons: ['OK']
          });
          alert.present();
        }
        }).then(() => {
						load = load +1;
						if(load >=2){
              loadingPopup.dismiss();
						}
        }); 
      return false;
  });
}


#4

I think this code is a complete disaster, so somebody else is going to have to try to help you.


#5

i think so :sob::sob::sob: