I have created a Dynamic Menu in ionic project and for each menu item I have to pass the API call to fetch the selected page-data.
- I have passed the ID of the menu clicked from
app.component.ts
toremote-service.ts
. - I need to fetch the data from the WordPress DB and i have found the API calls method.
app.html
<button menuClose ion-item *ngFor="let p of menuinformations" (click)="openApage(p.id)">
{{p.title.rendered}}
</button>
Here menuinformations
contains the JSON array of the pages that are to be displayed in the menu.
app.component.ts
openApage(pageinfo) {
var pagedetails = this.service.getSinglePage(pageinfo).subscribe(
data => {
this.pageinformations = data
});
console.log(pagedetails);
this.nav.push(AboutusPage, {
pageinfodetails: pagedetails
});
}
remote-service.ts
getSinglePage(pageinfo)
{
let options = new RequestOptions({ headers: this.headers })
let URL ="http://your-domain.com/wp-json/wp/v2/pages/"+pageinfo;
return this.http.get(URL).map(res => res.json());
}
I am successfully getting the page ID to the remote-service.ts
file. But unable to fetch the data from the api response.
When i paste the URL in the browser it fetches the data as JSON Format.
My need is that when I click on the menu an API call needs to be made and the data is to be fetched so what can i do for that.