Passing Data between pages as parameters


#1

I am new to ionic and angularjs and trying to display store information base on the id of the selected category so this my question how can I get the categoryid them pass it to my get request the retrieve the store data and display it

I try doing something like this

<ion-col width-25 no-margin no-padding *ngFor="let item of Category">
        <ion-card (click)="Store({{item categoryid}})">
          <img images-filter src="{{item.IMAGE}}" />
          <div class="card-description">
            <div card-title>{{item.NAME}}</div>
          </div>
        </ion-card>
      </ion-col>

and in the services did this

  GetOfferByID(ID){
    const ID = {CategoryID};
    this.GetID.push(ID);
    const headers = new Headers();
    headers.append('Content-Type','application/json; charset=utf-8');
    this.http.post('http://localhost:8888/PeopleService/GetStore&Offers/GetStore.php?CategoryID=ID',JSON.stringify(ID),headers).subscribe(

      ()=>{},
      err=>console.error(err)
    );
  }

and lastly this is my sql

<?php

        require_once'../db_config.php';


     
     $stringid=$_GET['CategoryID'];

     $arr = array();
 $sql = "SELECT store.NAME, pictures.PICPATH,store.WEBSITE ,store.DESCRIPTION ,`CATEGORYID`  FROM `store` LEFT JOIN pictures ON store.STOREID= pictures.STOREID WHERE store.CATEGORYID='$stringid'";
        $select_users = $conn->query($sql);
        if(!$select_users){
            die('Query Failed' . mysqli_error($conn));
        }
        while($row = $select_users->fetch_assoc()) {
            $arr[] = $row;

        } 


echo json_encode($arr);

?>

but as expected it did not work so I was wondering what is the correct way to do it


#2

For one thing, you’re calling http.post() when it looks like this should be a GET request (http.get()), as it is only retrieving data, does not modify state, and is idempotent.

For another, you don’t do anything with the result. You should not be subscribing in the provider; just returning the Observable you got from Http (transformed by map() as appropriate for your app). In the page, you subscribe to the return of getOfferById() and in that subscription you would assign it to the property you are looping across.

Incidentally, your naming conventions are all over the map. Generally-accepted JavaScript naming conventions are camelCase for properties and methods; PascalCase for classes and interfaces.


#3

I did make a GET request but still when I try to navigate to the store page I get only a blank page
how can I assign the CategoryID to the url ?CategoryID=ID so when I press the on Store() in the category page I get the details information in the store page


#4
http.get('/path/getstore?CategoryID=' + id)

#5

Yeah that work exactly like I wanted thank you so much