@@ -14,24 +14,46 @@ export class SimpleComboCascadingComponent implements OnInit {
1414 public countriesData : Country [ ] ;
1515 public regionData : Region [ ] = [ ] ;
1616 public citiesData : City [ ] = [ ] ;
17+ public isLoadingRegions : boolean = false ;
18+ public isLoadingCities : boolean = false ;
19+ private loadingTime = 0 ;
20+
1721 public ngOnInit ( ) : void {
1822 this . countriesData = getCountries ( [ 'United States' , 'Japan' , 'United Kingdom' ] ) ;
1923 }
2024
2125 public countryChanging ( e : ISimpleComboSelectionChangingEventArgs ) {
2226 this . selectedCountry = e . newSelection as Country ;
23- this . regionData = getCitiesByCountry ( [ this . selectedCountry ?. name ] )
27+ if ( e . newSelection ) {
28+ this . regionData = [ ] ;
29+ this . isLoadingRegions = true ;
30+ this . loadingTime = 2000 ;
31+ }
32+ setTimeout ( ( ) => {
33+ this . regionData = getCitiesByCountry ( [ this . selectedCountry ?. name ] )
2434 . map ( c => ( { name : c . region , country : c . country } ) )
2535 . filter ( ( v , i , a ) => a . findIndex ( r => r . name === v . name ) === i ) ;
36+ this . isLoadingRegions = false ;
37+ } , this . loadingTime )
2638 this . selectedRegion = null ;
2739 this . selectedCity = null ;
2840 this . citiesData = [ ] ;
41+ this . loadingTime = 0 ;
2942 }
3043
3144 public regionChanging ( e : ISimpleComboSelectionChangingEventArgs ) {
3245 this . selectedRegion = e . newSelection as Region ;
33- this . citiesData = getCitiesByCountry ( [ this . selectedCountry ?. name ] )
46+ if ( e . newSelection ) {
47+ this . citiesData = [ ] ;
48+ this . isLoadingCities = true ;
49+ this . loadingTime = 2000 ;
50+ }
51+ setTimeout ( ( ) => {
52+ this . citiesData = getCitiesByCountry ( [ this . selectedCountry ?. name ] )
3453 . filter ( c => c . region === this . selectedRegion ?. name ) ;
54+ this . isLoadingCities = false ;
55+ } , this . loadingTime )
3556 this . selectedCity = null ;
57+ this . loadingTime = 0 ;
3658 }
3759}
0 commit comments