【发布时间】:2020-09-04 10:48:54
【问题描述】:
我无法在选择列表中显示选项。 HTML 代码如下:
<select class="selectpicker" (change) = "searchCountry(selectedCountry)" [(ngModel)] = "selectedCountry" data-live-search="true" title = "Selecciona un país">
<option [ngValue]="object" *ngFor = "let object of countryList" >{{object.Country}}</option>
</select>
我要做的是显示 countryList 数组中对象的属性“Country”(这是一个字符串)。 问题是没有选项显示,选择列表是空的。
我确定问题不在于 countryList,因为如果我在 select 元素之外运行以下代码,Country 属性会正确显示。
<h2>{{countryList[0].Country}}</h2>
我也试过用类似下面的数组替换 countryList,它显示正确,所以我不确定问题出在选择列表上。
countryList: Country[] = ["Argentina", "Chile", "Ecuador];
会不会和countryList数组的长度有关?它有 186 个元素。
【问题讨论】:
-
无关,但尽量不要使用像
object或number这样的变量名。它们可能(或可能不会)干扰 JS 数据类型。你可以说countryObj。
标签: html angular html-select ngfor