0

In ngFor i have this:

let orderTracking of orderTrackings

And on some places i display data from orderTrackings, but on one place i have dropdown list.

<select  [(ngModel)]="selectDestination" (click)="orderTracking.selectDestination = selectDestination">
    <option value=""></option>
    <option *ngFor="let destination of destinationsTo" [value]="destination.code">{{destination.displayname}}</option>
</select>

What im trying to do is to add selected value in that specific object in array, because every of that objects might have different values from dropdown. So when i in my .ts file display orderTrackings array to have for example:

orderTracking[0].something = 'something'
orderTracking[0].selectDestination = 1

orderTracking[1].something = 'test'
orderTracking[1].selectDestination = 5 

And so on. Any suggestion how can i do that?

1 Answer 1

1

You can do this my setting the ngModel to orderTracking.selectDestination. Since [(ngModel)] is two way data binding everytime the user chooses a new option from the select, the selectDestination property of that particular orderTracking gets updated.

<select [(ngModel)]="orderTracking.selectDestination">
   ...
</select>

Here is a stackblitz demoing this.

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.