0

I am trying to have one static button in segment and remaining are dynamic my dynamic part is working but my static segment button is not showing all the product

here is my .html file

<ion-content >

    <ion-segment [(ngModel)]="kmart" color="primary">
        <ion-segment-button value="All">
          All
        </ion-segment-button>
        <ion-segment-button *ngFor="let tabName of buttonName" value={{tabName.product_type}}>
          {{tabName.product_type}}
        </ion-segment-button>
  </ion-segment>

  <div [ngSwitch]="kmart" *ngFor = "let demo of demoObj">
  <ion-list *ngSwitchCase="All">
        <ion-item>
          {{demo.name}}
        </ion-item>
    </ion-list>
    <ion-list *ngSwitchCase="demo.product_type">
        <ion-item>
          {{demo.name}}
        </ion-item>
    </ion-list>
</div>

</ion-content>

here is my .ts file

demoObj = [ {"product_id": "52","name": "Apple - Fuji","product_type": "Fruits"},
              {"product_id": "53","name": "bana - Fuji","product_type": "Fruits"},
              {"product_id": "54","name": "beetroot - Fuji","product_type": "Vegitables"},
              {"product_id": "55","name": "beens - Fuji","product_type": "Vegitables"},
              {"product_id": "56","name": "mango - Fuji","product_type": "Fruits"}
            ];
  buttonName = [{"product_type": "Fruits"},{"product_type": "Vegitables"}];

Question:

here at first time am able to display all the products but after switching to another segments and then i am come to 'All' segment I am not able to display any one can find any mistake.

Sangwin Gawande
  • 7,658
  • 8
  • 48
  • 66
Mohan Gopi
  • 7,606
  • 17
  • 66
  • 117

1 Answers1

0

I think that value='All' and *ngSwitchCase="All" is not matching probably that was causing error

You are right in your assumption. In order to set switch case as string literal you need to give single quotes within the double quotes.

 <ion-list *ngSwitchCase="'All'">
        <ion-item>
          {{demo.name}}
        </ion-item>
    </ion-list>
Sangwin Gawande
  • 7,658
  • 8
  • 48
  • 66
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103