首页 > 解决方案 > 无法使用 ng-repeat 获取下拉列表中的数据

问题描述

我正在尝试从角度值列表中显示下拉列表。但是当我尝试使用 ng-repeat 时出现错误,我无法理解问题所在

app.component.html

<h1>hi </h1>

<br><br><br>

<select>
  <option ng-repeat="x in names">{{x}}</option>
</select>

app.component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {

  names = ["Pending", "Out for delivery", "Delivered"];

  title = 'dropdownproj';
}

有人可以帮我解决这个问题。这可能是一个愚蠢的错误,但我无法抓住它。帮助!

我得到的错误

Property 'x' does not exist on type 'AppComponent'.

标签: angular

解决方案


试试这个

<select>
        <option *ngFor="let x of names" [value]="x">
          {{x}}
        </option>
    </select>

推荐阅读