简体   繁体   中英

Populate state and cities based on country and states selection at angular2-multiselect

I wanted to load state and city based on country selection. I am loading json data from json file with service https://raw.githubusercontent.com/sagarshirbhate/Country-State-City-Database/master/Contries.json . I have created full code at stacblitz here is url https://stackblitz.com/edit/create-jvxcbx please help me for this

load state based on the country as below.

write this in getCountries();

this.allCountries = data2.Countries;

declare the below variable.

allCountries:any = [];

write code on selection of country.

onItemSelect1(item: any) {
    console.log(item);
    console.log(this.selectedItems1);
    this.dropdownList2 = this.allCountries.map(x=>item.itemName == x.CountryName);
    console.log(this.dropdownList2);//implement in your state dropdown
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM