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

158
Views
¿Cómo pasar variables de la opción de selección a la función TypeScript en Angular?

bucle de opción de selección en myComponent.html:

 <select class="form-select" (change)="selectOption($event)"> <option *ngFor="let entity of entities; let i = index" value="{{entity.id}}" [selected]="i == 0 ? true : null" (onload)="fooFunction(i, entity.id)">{{entity.name}} </option> </select>

y la función myComponent.ts:

 fooFunction(i: number, entityId: number){ console.log(`${i} - ${entityId}`); }

Quiero pasar variables para que funcionen mientras relleno las opciones. Intenté load , onload , onSelect , etc.

¿Cómo puedo lograr esto en angular13 ?

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

Su selectOption($event) podría reflejar eso al pasar sus variables en una matriz al cambiar.

En TS

 @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: ['./app.component.css'], }) export class AppComponent { entities = [ { id: 1, name: 'hello' }, { id: 2, name: 'test' }, ]; selectOption(event: any) { const arr = event.target.value.split(','); console.log(arr[0]); //id console.log(arr[1]); //index } }

html

 <select class="form-select" (change)="selectOption($event)"> <option *ngFor="let entity of entities; let i = index" [value]="[entity.id, i]"> {{ entity.name }} </option> </select>

Ejemplo de trabajo: https://stackblitz.com/edit/angular-ivy-qzdsfl?file=src%2Fapp%2Fapp.component.ts

about 4 years ago · Santiago Gelvez Report

0

Tienes que usar ngModel

 <select class="form-select" [(ngModel)]="selectedValue"> <option *ngFor="let entity of entities; let i = index" [ngValue]="entity.id">{{entity.name}} </option> </select>
about 4 years ago · Santiago Gelvez 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!