angular - How to detect changes in a list of drop down elements? -


i have list of users. each user composite object: { id: '123', name: 'bob', state: 'colorado' }

i render users using *ngfor:

<div *ngfor="let u in users">     {{ u.name }}     <select [(ngmodel)]="u.state">        <option *ngfor="let s in states" [value]="s">{{s}}</option>     </select> </div> 

when select-value changes - want save object on rest api.

i tried adding (change)="changestate(u)", not work, apparently u.state being updated after (change) callback executed.

if not have loop, give dropdown reference: #state , use (change)="changestate(u, state.value)"

is option use $event.target.value? or there slicker way this? solution takes away validation.

is of first 2 solution attempts salvageable?

you can separate ngmodelchange event ngmodel:

<select [ngmodel]="u.state" (ngmodelchange)="changestate($event)">        <option *ngfor="let s in states" [value]="s">{{s}}</option> </select> 

then new select value passed changestate() directly.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -