0
  1. I want to see a single data as you can see in the picturesenter image description here

TypeScript

onQualityControlWareHouseStock(item)
      {    
         alert(item)
        this.qualitycontrolservice.getWareHouseStock(item).subscribe((x:any) =>  {
          this.qualityControlWareHouseStock = x.Result;   
                               
       })
      }

Html

<select>                        
    <option *ngFor="let binCode of qualityControlWareHouseStock" [ngModel]="binCode.BinCode" ngDefaultControl>{{binCode.BinCode}}</option>
 </select>

WareHouse model have BinCode field

  • do you mean that you want a single option in your select? – Dries Meerman Nov 10 '21 at 14:32
  • The image shows the same value duplicated many times from the service, which should be filtering out the values uniquely. – Andrew Halil Nov 10 '21 at 14:55
  • This link may help [Get all unique values](https://stackoverflow.com/questions/1960473/get-all-unique-values-in-a-javascript-array-remove-duplicates) – Fateh Nov 10 '21 at 14:58

1 Answers1

0

Since your using an Observable you can get the first return with take(1). This will unsubscribe from your Observable as soon as one Value is emitted

this.qualitycontrolservice.getWareHouseStock(item).pipe(take(1)).subscribe(
(x:any) =>  {
        this.qualityControlWareHouseStock = x.Result;   
}

Another solution if you only want to return a Element once but more than one you can to only store unique entries

function onlyUnique(value, index, self) {
  return self.indexOf(value) === index;
}

this.qualitycontrolservice.getWareHouseStock(item).pipe(take(1)).subscribe(
(x:any) =>  {
        this.qualityControlWareHouseStock = x.Result.filter(onlyUnique);   
}