【问题标题】:How can I make a map in Angular?如何在 Angular 中制作地图?
【发布时间】:2021-06-12 21:24:24
【问题描述】:

如何实现 .map 的 react with angular。

React 示例:

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

我如何使用角度组件来做到这一点?

【问题讨论】:

  • 你需要使用*ngFor来显示listA related post.
  • &lt;select&gt; &lt;option *ngFor="let item of options"&gt;{{item}}&lt;/option&gt; &lt;/select&gt; (angular.io/api/common/NgForOf#description)
  • 1. AngularJS != Angular2+。 2. 如果您是 Angular 新手,我建议您阅读他们的快速教程 here。它介绍了一些基础知识。

标签: angular typescript


【解决方案1】:

在您的 component.ts 文件中

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

在您的 component.html 文件中

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

这里是 StackBlitz https://stackblitz.com/edit/angular-ivy-nrzght

【讨论】:

    猜你喜欢
    • 2017-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多