如何在 Angular 6 中创建级联下拉列表(国家/地区和州列表)。我想要在 Angular 6 中创建一个完整的国家/地区和州列表。
任何知道这一点的人请分享你的想法。
演示---->级联下拉菜单(国家和州列表) https://stackblitz.com/edit/angular-qvqqgc
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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)