[Fixed] How can I make a map in Angular?

Issue

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?

Solution

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

Leave a Reply

(*) Required, Your email will not be published