Angular 省市区级联
2021-01-13 14:35 qgbo 阅读(310) 评论(0) 收藏 举报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>
气功波(18037675651)
浙公网安备 33010602011771号