0

I am very new to use of promises in JS. I have a main function which is returning an array consisting 3 different arrays.

filterAllComponent(inputdata) {
  this.getplaceArray= this.getfilterPlaces(inputdata);
  this.getTransporterArray= this.getfilterTransporter(inputdata);
  this.getVehicleArray= this.getfilterVehicles(inputdata);
  this.AllDropdownValues= this.getTransporterArray.concat(this.getVehicleArray).concat(this.getplaceArray);
  console.log("All Arrays",this.AllDropdownValues);
}

to populate one of the array "getfilterPlaces", I am using the subscribe function:

getfilterPlaces(autocompleteInputData) {
  if (autocompleteInputData == '' || typeof(autocompleteInputData) == 'object') 
  return null;
  this.placeData.getPlacesFromPig(autocompleteInputData)
  .subscribe(response => {
        return this.ResponseResult(response);
   }); 

}

function getfilterPlaces is returning undefined while the rest of the array is coming fine. I suppose this is because while the other array are populated, getfilterPlaces** still is not completed. Now I have an option of using promise in which the other arrays will not be populated until array getfilterPlaces is completed first. Please help me finding a right approach to use Promise function. I am not finding where to start.

Joe Warner
  • 3,335
  • 1
  • 14
  • 41
Udit Gogoi
  • 675
  • 2
  • 11
  • 28

0 Answers0