@@ -14,24 +14,46 @@ export class SimpleComboCascadingComponent implements OnInit {
14
14
public countriesData : Country [ ] ;
15
15
public regionData : Region [ ] = [ ] ;
16
16
public citiesData : City [ ] = [ ] ;
17
+ public isLoadingRegions : boolean = false ;
18
+ public isLoadingCities : boolean = false ;
19
+ private loadingTime = 0 ;
20
+
17
21
public ngOnInit ( ) : void {
18
22
this . countriesData = getCountries ( [ 'United States' , 'Japan' , 'United Kingdom' ] ) ;
19
23
}
20
24
21
25
public countryChanging ( e : ISimpleComboSelectionChangingEventArgs ) {
22
26
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 ] )
24
34
. map ( c => ( { name : c . region , country : c . country } ) )
25
35
. filter ( ( v , i , a ) => a . findIndex ( r => r . name === v . name ) === i ) ;
36
+ this . isLoadingRegions = false ;
37
+ } , this . loadingTime )
26
38
this . selectedRegion = null ;
27
39
this . selectedCity = null ;
28
40
this . citiesData = [ ] ;
41
+ this . loadingTime = 0 ;
29
42
}
30
43
31
44
public regionChanging ( e : ISimpleComboSelectionChangingEventArgs ) {
32
45
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 ] )
34
53
. filter ( c => c . region === this . selectedRegion ?. name ) ;
54
+ this . isLoadingCities = false ;
55
+ } , this . loadingTime )
35
56
this . selectedCity = null ;
57
+ this . loadingTime = 0 ;
36
58
}
37
59
}
0 commit comments