1

I am new to Ionic. I want to access the a particular value from WordPress rest API.

I want to access this value from api. title: rendered: "04:00 PM – 07:00 PM"

.ts file

 viewTime(){

   let url = '';


    this.http.get(url, this.config.options)
    .map(res => res.json())
        .subscribe((response: any) => {
            console.log(response)
            console.log(response.title)

                            }, (err) => {
                            let alert = this.alertCtrl.create({
                            title: 'Error',
                            subTitle: 'Please check your credentials',
                            buttons: ['OK']
                                    });
                             alert.present();
                             });
                             }

But console.log(response.title) gives undefined.

2 Answers 2

1

It seems to be an array, so you have to loop over collection to get access to each element of an array.

this.http.get(url, this.config.options)
.map(res => res.json())
    .subscribe((response: any) => {
      this.items = response;
      response.forEach(item => console.log(item.title))
    });

View

<ion-item>
   <ion-label>Select Time</ion-label>
      <ion-select  interface ="popover">
        <div *ngFor="let item of items">
           <ion-option > {{item.title.rendered}}</ion-option>
        </div>
      </ion-select>
</ion-item>
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks you sir solve my problem..Can you tell me how to access these title value in ion-select..?have you any idea
@Saifkhan you want to populate an value?
Yes sir using ion-select. and sir how to remove this ' &#8211;' with - between two time slot.
0

To display the time slot correct, you can use something like this:

 <p [innerHTML]="item.title.rendered"></p>

like in the above example, do something like this:

let times: string[];
response.forEach(item => times.push(item.title.rendered);

Then in HTML:

<ion-select [(ngModel)]="data.selectedTime" multiple>
  <ion-option *ngFor="#time of times" [value] = "time" [checked]="false">{{time}}   </ion-option>
</ion-select>

3 Comments

Is it not working in a ion-select or also not working in a normal <p> in the ion-content?
not working try with ion-select.i have not try with ion-content.
<ion-item> <ion-label>Select Time</ion-label> <ion-select interface ="popover"> <div *ngFor="let item of items"> <ion-option > {{item.title.rendered}}</ion-option> </div> </ion-select> </ion-item>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.