gpt4 book ai didi

angular - 如何在 Angular 6 中创建级联下拉列表(国家和州列表)

转载 作者:行者123 更新时间:2023-12-03 20:29:51 24 4
gpt4 key购买 nike

如何在 Angular 6 中创建级联下拉列表(国家和州列表)。我想要一个完整的国家/地区和 Angular 6 中的州列表。

任何知道请分享您的想法的人。

最佳答案

演示 ----> Cascading Drop Down (Country and State list)

HTML:

<label>Country</label>
<div title="Please select the country that the customer will primarily be served from">
<select placeholder="Phantasyland" (change)="changeCountry($event.target.value)">
<option *ngFor ="let count of countryList">{{count.name}} </option>
</select>
</div>


<label>City</label>
<div title="Please select the city that the customer is primarily to be served from.">
<select placeholder="Anycity">
<option *ngFor ="let city of cities">{{city}} </option>
</select>
</div>

TS:
countryList: Array<any> = [
{ name: 'Germany', cities: ['Duesseldorf', 'Leinfelden-Echterdingen', 'Eschborn'] },
{ name: 'Spain', cities: ['Barcelona'] },
{ name: 'USA', cities: ['Downers Grove'] },
{ name: 'Mexico', cities: ['Puebla'] },
{ name: 'China', cities: ['Beijing'] },
];
cities: Array<any>;
changeCountry(count) {
this.cities = this.countryList.find(con => con.name == count).cities;
}

关于angular - 如何在 Angular 6 中创建级联下拉列表(国家和州列表),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51817557/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com