0

Hi I am having below array where I need to show only codes in dropdown where status:active I tried using ngif in options tag like *ngIf="c.status=='Active'" but not working how to show only active objects.

<select class="form-control" [(ngModel)]="addproduct.code">
     <option *ngFor="let c of allProducts"  [value]="c.code" id="{{c.code}}">{{ c.code }}</option>
</select>

In component :

  getAllProducts(){
      this.superuserViewAccountpreferencessService.getProductDetails().subscribe(
        res => {
          this.allProducts = res['products'];
        }
      )
    }

i will get response as:

[{
    "code": "PLATINUM",
    "status": "Active",
    "cost": 100
}, {
    "code": "PlatinumTe",
    "cost": 123
}, {
    "code": "Test11",
    "cost": 1234
}, {
    "code": "PLATINUM22",
    "status": "Active",
    "cost": 1000
}]
Sudhir MN
  • 125
  • 8

1 Answers1

1

I would just filter out the items that have status === 'Active' before you store them in your property

this.allProducts = res['products'].filter(item => item.status === 'Active');
LLai
  • 13,128
  • 3
  • 41
  • 45