Object id passing in an API get request


#1

Hello,
I have a get request from an API call that i want to submit to the server with the object id, am having difficulties passing this id in the function.
on call on the function, it should update this item on the server

<ion-content padding *ngIf="ride">
	<button ion-button outline style="margin-left: 15px;background-color:#32c5d2;color:#fff;" (click)="publishRide(id)" >Publish Ride</button>

<p>Origin : {{ ride.origin }} </p>
<p>Destination : {{ ride.destination }} </p>
<p>Price : {{ ride.price }} </p>

</ion-content>

this is the function call

 publishRide() 
{

    this.showLoader();
    this.rideService.unpublsihRide().then((result) => {
      this.loading.dismiss();
      this.navCtrl.pop();
    }, (err) => {
      this.loading.dismiss();
      this.presentToast(err);
      console.log(err);
    });
  }

#2

Hi,

In your html you call publishRide(id)
But in your ts file that function does not take any param

So how should that function take that id to the Api?


#3

I did in the original example, it’s just an error not adding it here.
A simple demonstration will help. Thanks


#4

At first it would be helpful if you let me know what id you want to submit to the server.
At the moment you are calling publishRide(id) from your button. But this id isn’t known within your template.

As an example:

{{item.name}}

In this example item is an object with the properties id and name. So the item’s id can be submitted to the function publishRide(id).

At the moment for me it is not clear what id you want to submit. Maybe you could clarify that.


#5

This is the process;

  1. Register a product

  2. I pushed the product response from the server to the page your presently seeing. On that set page it contains the id alongside other parameters

  3. the publishRide(id) button is just supposed to get that id gotten from that response and set a field on my database to 1 based on the id.

  4. Handling the id on that page for submit is the problem an facing.

my server gives me this error with the following code

at HandleExceptions->handleError(8, ‘Trying to get property of non-object’, ‘/opt/lampp/htdocs/takwidexpress/api/takwidexpress/app/Http/Controllers/RidesController.php’, 99, array(‘id’ => ‘id’, ‘ride’ => null))
which is a property of non object. the null is suppose to be that id


#6

When you receive data from your server I think you will store that data in a local object. Something like this:

Datafromserver.subscribe(result => {
This.data =result;
}

You should now be able to use this.data.id. There should be no need to provide that id by the button click Event.


#7

OK, thanks very much. I will try it out and let you know how it goes