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

406
Views
Angular how can I get selected options (multiple)

I'm literally looking for the solution to this problem for two days and I can't find a thing... Basically what I want is to get selected options from my <select> element:

<select name="selectedCars" [ngModel]="selectedCars" multiple>
    <option *ngFor="let car of cars" [ngValue]="car">{{car.Model}}</option>
</select>

I thought it would bind to selectedCars: Car[] and I could do something like this to display selected values:

<h2>Selected:</h2>
<ul>
    <li *ngFor="let selectedCar of selectedCars">{{selectedCar.Model}}</li>
</ul>

There's literally nothing in the documentation about this.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Change [ngModel] to [(ngModel)](two way binding) which will update selectedCars array as soon as you select / unselect and option in drop-down.

<select name="selectedCars" [(ngModel)]="selectedCars" multiple>
    <option *ngFor="let car of cars" [ngValue]="car">{{car.Model}}</option>
</select>

Otherwise do add below attribute to your select element shown below, it is one as the same thing doing [(ngModel)].

(ngModelChange)="selectedCars=$event"
about 4 years ago · Santiago Trujillo Report

0

You should use [(ngModel)]

<select name="selectedCars" [(ngModel)]="selectedCars" multiple>
          <option *ngFor="let car of cars" (click)="clickedOption()" [ngValue]="car">
          {{car.name}}</option>
      </select>

clickedOption(){
    console.log(this.selectedCars)
  }

You can simply log the elements when ever an option is clicked as shown in the above method

LIVE DEMO

about 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!