1.数据来源:https://github.com/airyland/china-area-data
选择那个 数组
Angular 代码如下:
export class AppComponent { title = 'test'; provinces = []; province; cities = []; city; ngOnInit() { console.log(123); this.provinces=this.arr.filter(t=>!t.parent); } change(event) { console.log(event); this.cities=this.arr.filter(t=>t.parent==event); } } <select (change)="change(pro.value)" #pro [(ngModel)]="province" > <option value="{{p['value']}}" *ngFor="let p of provinces">{{p["name"]}}</option> </select> <select name="" id="" [(ngModel)]="city"> <option value="{{p['value']}}" *ngFor="let p of cities">{{p["name"]}}</option> </select>