-1

How to achieve a .map of react with angular.

Example at React:

const options = ['Car', 'Bus', 'Truck', 'Bike', 'Motorcycle'];
const compTest = () => (
  <select>
    {options.map((vehicle) => <option>{vehicle}</option>)}
  </select>
)

How I do this with an angular component?

Philipp Meissner
  • 5,273
  • 5
  • 34
  • 59
  • You need to use `*ngFor` to display [list](https://angular.io/tutorial/toh-pt2). [A related post](https://stackoverflow.com/q/35513049/2873538). – Ajeet Shah Mar 15 '21 at 15:32
  • `` (https://angular.io/api/common/NgForOf#description) – Martin Mar 15 '21 at 15:37
  • 1
    **1.** AngularJS != Angular2+. **2.** If you're new to Angular, I'd recommend you to go through their quick tutorial [here](https://angular.io/tutorial). It introduces some of the basics. – ruth Mar 15 '21 at 16:03

1 Answers1

0

In your component.ts file

options = ['Car', 'Bus', 'Truck', 'Bike', 'Motorcycle'];

in your component.html file

<select>
  <option *ngFor="let option of options">{{option}}</option>
</select>

and here is StackBlitz https://stackblitz.com/edit/angular-ivy-nrzght

Sanka Sanjeewa
  • 1,993
  • 14
  • 16