Angular 省市区级联

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)
原文地址:https://www.cnblogs.com/qgbo/p/14271882.html