angular - 无法使用 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'.
解决方案
试试这个
<select>
<option *ngFor="let x of names" [value]="x">
{{x}}
</option>
</select>
推荐阅读
- python - Python Google Cloud Storage 连接器单元测试
- javascript - 获取 4 个唯一文档 mongodb 的最高最大值(平均值)
- git - 每当我尝试推送到 repo 时,都会收到 GitHub 登录界面的提示
- regex - .htaccess 重写规则不适用于子文件夹
- javascript - 在 div 中使用背景颜色时,Jcrop 不显示图像
- javascript - Webpack-dev-server 是与 Webpack 一起用作服务器的最佳实践,还是单独使用?
- javascript - 找到匹配属性时从数组中删除对象
- powershell - AzureAD Powershell 将一个用户组成员身份复制到另一个用户
- numpy - Numpy按列表切片多个维度
- reactjs - 反应:'db' 不是从'../firebase' 导出的