# Any suggestion for make this work?

**URL:** <https://forum.ionicframework.com/t/any-suggestion-for-make-this-work/163890>\
**Category:** ionic-v3\
**Created:** [May 14, 2019, 7:06pm UTC](https://forum.ionicframework.com/t/any-suggestion-for-make-this-work/163890 "2019-05-14T19:06:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fares95](https://avatars.discourse-cdn.com/v4/letter/f/6bbea6/32.png) [@Fares95](https://forum.ionicframework.com/u/Fares95)\
**Post date:** [May 14, 2019, 7:06pm UTC](https://forum.ionicframework.com/t/any-suggestion-for-make-this-work/163890/1 "2019-05-14T19:06:06Z")

</div>

Hello ,  
i was trying to read a value by ionic storage and post it to data base by hhtp post but it seems thatit’s posted empty to the database …

any thing i am missing?

```auto
import { Component } from '@angular/core';
import { NavController , ToastController, App, ActionSheetController} from 'ionic-angular';
import { ReclamationPage} from '../reclamation/reclamation';
import { Http, Headers, RequestOptions } from '@angular/http';
import { PostProvider } from '../../providers/post-provider';
import { GetProvider } from '../../providers/get/get';
import { Storage } from '@ionic/storage';
import 'rxjs/add/operator/map';
import { Observable } from 'rxjs/Observable';

@Component({
  selector: 'page-suivre-reclamation',
  templateUrl: 'suivre-reclamation.html',
})

export class SuivreReclamationPage {
 
  items: any;
  public dt: any;

  cin: string ="";
  rec_id: string ="";
  type_rec: string ="";
  description: string ="";
  adresse: string="";
  laptitude: any;
  longitude: any;
  etat_rec: string ="";
  datetime: string=""
  gouvernorat: string ="";
  commune: string="";
  cin_admin: string=""
  postal: string="";
  fichiers: string="";
  myphoto:any;

  constructor(public navCtrl: NavController, private postPvdr: PostProvider, public http: Http,
    public storage: Storage , public toastCtrl: ToastController, appCtrl: App,
    public actionSheetCtrl: ActionSheetController ){

    this.storage.get('session_storage').then((result) => {
      this.dt = result;
      this.cin = this.dt[0].cin;
      console.log(this.cin + 'here');
    });
    this.load(this.cin);
    console.log(this.cin + ' here 2');

    }

    //evenement d'entrée
    ionViewWillEnter()
    {

      console.log('ionViewWillEnter SettingsPage');
     
    }

    load(cin_: string)
    {
      let body = {
        cin: cin_ ,
        aksi: 'suivre_reclamation'
      }
      console.log(body);

      this.postPvdr.postData(body) .subscribe(data => {
           this.items= data.items;
        console.log(data.items);
      });
    }

    onSuivre()
    {
      this.navCtrl.push(ReclamationPage);
    }

  }

```

the result :

 ![Capture](https://global.discourse-cdn.com/ionicframework/original/3X/f/a/fa15efeae301209b52ccf46bd628017fda870cb0.png)

---

<div class="post-metadata">

**Author:** ![VictorNorman](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/victornorman/32/124743_2.png) [@VictorNorman](https://forum.ionicframework.com/u/VictorNorman)\
**Post date:** [May 14, 2019, 11:40pm UTC](https://forum.ionicframework.com/t/any-suggestion-for-make-this-work/163890/2 "2019-05-14T23:40:41Z")

</div>

Is the value you want to post via http `this.cin` ? And, do you think it is empty because you just see `here 2` in the output?

If so, the problem, I think, is that your call to `this.storage.get()` returns a Promise, which you then handle with `then()`. So, the function passed to `then()` happens when the promise is resolved – not immediately. However, your code goes on and prints `this.cin` is not resolved yet.

The solution, I think, is to put your call to `this.load(this.cin)` into the then() function:

```auto
this.storage.get('session_storage').then((result) => {
      this.dt = result;
      this.cin = this.dt[0].cin;
      console.log(this.cin + 'here');
      this.load(this.cin);
    });

```

That way the call to `load` will only be done when the result has been resolved.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![sonicwong](https://avatars.discourse-cdn.com/v4/letter/s/aeb1de/32.png) [@sonicwong](https://forum.ionicframework.com/u/sonicwong)\
**Post date:** [May 15, 2019, 9:27am UTC](https://forum.ionicframework.com/t/any-suggestion-for-make-this-work/163890/3 "2019-05-15T09:27:52Z")

</div>

> [@Fares95](#):
>
> load(cin\_: string) { let body = { cin: cin\_ , aksi: ‘suivre\_reclamation’ } console.log(body); this.postPvdr.postData(body) .subscribe(data =\> { this.items= data.items; console.log(data.items); }); }

I suggest u to make any HTTP call inside/after ionViewDidEnter(){ … }.
