Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

236
Views
Angular 2 ngModelChange opción de selección, toma una propiedad específica

Tengo un formulario de selección desplegable en angular 2.

Actualmente: cuando selecciono una opción, el option name de la opción pasa a mi función onChange como $event

Se busca: cuando selecciono una opción, me gustaría pasar el workout.id a mi función onChange .

¿Cómo puedo lograr eso?

 <select class="form-control" [ngModel]="selectedWorkout" (ngModelChange)="onChange($event)"> <option *ngFor="#workout of workouts">{{workout.name}}</option> </select>

Controller

 onChange(value){ alert(JSON.stringify(value)); }
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

<select class="form-control" [ngModel]="selectedWorkout" (ngModelChange)="onChange($event)"> <option *ngFor="#workout of workouts" [value]="workout.id">{{workout.name}}</option> </select>

O

 <select class="form-control" [(ngModel)]="selectedWorkout" (change)="onChange($event.target.value)"> <option *ngFor="#workout of workouts" [value]="workout.id" >{{workout.name}}</option> </select>

Mira esto

over 4 years ago · Santiago Trujillo Report

0

también podría usar [ngValue] dentro de la opción:

 <select class="form-control" [ngModel]="selectedWorkout" (ngModelChange)="onChange($event)"> <option *ngFor="#workout of workouts" [ngValue]="workout">{{workout.name}}</option> </select>
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!