Angular setValue is not working on first call on primeng dropdown

Viewed 24

I'm using angular reactive forms and primeng dropdown. When user select a customer I'm fetching customer data and assigning cityId and townId properties of customer to primeng dropdown. Dropdown value lists are cityList and townList and they are being fetched from an API and townList is being fetched according to cityList. So cityId is being assigned to dropdown correctly but townId is not being assigned if I don't select same customer again(The form value is not chaning)

 setCustomerInfo(customer: Customer) {
if (!this.orderMaster?.id) {
  this.form.get('billShipmentAddress').setValue(customer.address);
  this.form.get('billShipmentCityId').setValue(customer.cityId);
  this._comboService
  .getTownlist(customer.cityId)
  .subscribe((res)=>{
     this.townList = [...res]
     this.form.get("billShipmentTownId").setValue(customer.townId);
     console.log(this.form.value);
  })
  this.form.get('billShipmentPostCode').setValue(customer.postCode);
}}

This is the place where I assign customer info to dropdowns. As you see I'm fetching townList with getTownList function.

0 Answers
Related