0

I want to access array data and display this data in ion-select.

html

<ion-item>
   <ion-label>Select Time</ion-label>
      <ion-select  interface ="popover">
        <div *ngFor="let item of items">
           <ion-option > {{item}}</ion-option>
        </div>
      </ion-select>

ts file

ionViewDidLoad(){

   let url = 'http://mysiteurl/wp-json/wp/v2/authores/4';

    this.http.get(url, this.config.options).map(res => res.json())
          .subscribe((response: any) => {
              this.items = response;
              response.forEach(item => 
              console.log(this.item));
       }, (err) => {
           let alert = this.alertCtrl.create({
           title: 'Error',
          subTitle: 'Please check your credentials',
          buttons: ['OK']
          });
      alert.present();
    });
   }
 }

and this is my api response

[
"09:00 AM -12:00 PM",
"12:00 PM - 03:00 PM",
"05:00 PM - 07:00 PM"
]

enter image description here

How to access these values in my ion-select option.I am not able to do that.

4
  • console.log(this.item) is invalid. Do you want to just print item or this.items? Commented Oct 19, 2018 at 9:25
  • i just want these values in ion-select.. Commented Oct 19, 2018 at 9:28
  • What does console.log(response) print just inside subscribe? Commented Oct 19, 2018 at 9:29
  • console.log(response) print whole response .i attached the image of my response in above question...the image showing the console.log(response). Commented Oct 19, 2018 at 9:34

1 Answer 1

1

@saif khan.. remove spaces in your html

 <ion-item>
       <ion-label>Select Time</ion-label>
          <ion-select [(ngModel)]="item" interface ="popover">
            <div *ngFor="let item of items">
               <ion-option>{{item}}</ion-option>
            </div>
          </ion-select>

and then in the component

 this.http.get(url, this.config.options)
    .map(res => res.json()).subscribe((response: any) => {
          this.items = response;   //this will store your response in items
          response.forEach(item => {
          //if you want print each item in the console
          console.log(item);
           });
        });
Sign up to request clarification or add additional context in comments.

1 Comment

[ngMode)]="item" is missing in <ion-select interface ="popover">

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.