John Theoden
John Theoden

Reputation: 325

push properties in array from dropdown and input - Angular 2

I have row of input fields and dropdowns. I can generate new row by clicking on button "Add row". I managed via "i of index" to get values for every input in that row, but I am unable to do that for dropdowns (also i get error when i select item from dropdown). When you fill inputs and select from dropdowns you can see result in console log after pressing button.

Plunker: Plunker

console.log example:

(2) [{…}, {…}]

0 : {name: "A", data: "123", num: "", char: ""} 1 : {name: "B", data: "123", num: "", char: ""}

Perhaps there is some other solution...

Upvotes: 0

Views: 1185

Answers (1)

user4676340
user4676340

Reputation:

Why don't you just use the ng model property on it ?
Something like in this plunkr

<select [(ngModel)]="this.properties[i].num">
  <option selected disabled>Select type</option>
  <option *ngFor="let type of numberTypes">{{type}}</option>
</select>

<select [(ngModel)]="this.properties[i].char">
  <option selected disabled>Select type</option>
  <option *ngFor="let type of charTypes">{{type}}</option>
</select>

Upvotes: 2

Related Questions