Angular2 влияет на несколько выпадающих
У меня есть два выпадающих на моей странице.
Один Country
и другое City
, Как есть "Please Select"
в качестве значения по умолчанию.
Когда пользователь изменяет значение в Country
соответствующие города правильно заселены в City
,
Однако, когда пользователь нажимает edit record
значок из сетки на странице соответствующее значение заполняется в Country
выпадающий но City
выпадающее значение всегда остается "Please Select"
,
public onCountryChangeEvent(slectedCountryId): void {
this.populateCityListByCountry(slectedCountryId);
}
private populateCityListByCountry(countryId: Number) {
var city: City = new City();
city.cityId = AppConstants.PLEASE_SELECT_VAL;
city.cityName = AppConstants.PLEASE_SELECT_STR;
const cityCombo: FormControl = (<any>this.myForm).controls.cityId;
if(AppUtility.isEmpty(countryId)){
this.cityList=[];
this.cityList.unshift(city);
cityCombo.reset();
} else {
this.listingService.getCityListByCountry(countryId)
.subscribe(
restData => {
if(AppUtility.isEmpty(restData)){
this.cityList=[];
this.cityId=null;
this.city=null;
}
else{
this.cityList = restData;
if(!AppUtility.isEmptyArray(this.cityList)){
if(!this.isEditing){
this.cityId = this.cityList[0].cityId;
this.city=this.cityList[0].cityName;
}
}
}
this.cityList.unshift(city);
},
error => {this.errorMessage = <any>error;},
()=> {
cityCombo.reset();
}
);
}
}
<label for="countryId" class="col-md-3 col-xs-12 form-control-label text-md-right">Country</label>
<div class="col-md-8 col-xs-12">
<wj-combo-box id="countryId" tabindex="3" formControlName="countryId" class="form-control" [isEditable]="false" [itemsSource]="countryList"
displayMemberPath="countryName" (ngModelChange)="onCountryChangeEvent($event)" selectedValuePath="countryId" [(ngModel)]="countryId"
required></wj-combo-box>
</div>
<wj-combo-box id="cityId" tabindex="4" formControlName="cityId" class="form-control" [isEditable]="false" [itemsSource]="cityList"
displayMemberPath="cityName" selectedValuePath="cityId" [(ngModel)]="cityId" required></wj-combo-box>