1

I load data from an API and bind the values i get into textfields which has a loop method on it. Secondly what i want to do is when the values are been shown on the page and i submit click is click, it should post all the values to the console.

API

   this.http.get('http://localhost/scripts/test.php?year='+this.navparams.data.Quest_Year).map(res => res.json()).subscribe(data =>{
                console.log(JSON.stringify(data));
                this.items= data;
            });

HTML

<div *ngFor="let item of items">
<ion-input  type="text"  [(ngModel)]="item.Quest_ID"></ion-input>
</div>
<button (click)="send()"> Sample</button>

JS

  send(){
    for(var i=0;i<this.test.length;i++) {
    console.log(item.Quest_ID[i])
    }

    }
1
  • what did you try ? any errors ? Commented Nov 22, 2017 at 23:38

1 Answer 1

1

looks like your model is bound to item.Quest_ID which is an element in the items array, so, you should be doing this:

send(){
    for(var i=0;i<this.items.length;i++) {
        console.log(this.items[i].Quest_ID);
    }
}

to log them all to console.

or if you want to be cooler:

send(){
    this.items.forEach(item => console.log(item.Quest_ID));
}
Sign up to request clarification or add additional context in comments.

Comments

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.