# Ion Segment - ngSwitch - switch case only accepts string

**URL:** <https://forum.ionicframework.com/t/ion-segment-ngswitch-switch-case-only-accepts-string/50508>\
**Category:** ionic-v3\
**Created:** [April 27, 2016, 4:47am UTC](https://forum.ionicframework.com/t/ion-segment-ngswitch-switch-case-only-accepts-string/50508 "2016-04-27T04:47:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![JosephMendez](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/josephmendez/32/99103_2.png) [@JosephMendez](https://forum.ionicframework.com/u/JosephMendez)\
**Post date:** [April 27, 2016, 4:47am UTC](https://forum.ionicframework.com/t/ion-segment-ngswitch-switch-case-only-accepts-string/50508/1 "2016-04-27T04:47:09Z")

</div>

No error showing the switching is not working.

`

```
     <div padding>
     <ion-segment [(ngModel)]="homeSegment" (change)="onSegmentChanged($event)" danger>
    <ion-segment-button *ngFor="#item of fetchCatch; #x = index" [value]="x" secondary>
    {{item.name}}
   </ion-segment-button>
   </ion-segment>
 </div>
 <div [ngSwitch]="homeSegment">
   <ion-list *ngFor="#itemx of fetchCatch; #i = index" *ngSwitchWhen="'i'">
     <ion-item *ngFor="#itemchild of itemx.children" (click)="categoryDetails(itemchild)">
       <h2>{{itemchild.name}}</h2>
     </ion-item>
   </ion-list>
  </div>`
```

---

<div class="post-metadata">

**Author:** ![pivalig](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/pivalig/32/100053_2.png) [@pivalig](https://forum.ionicframework.com/u/pivalig)\
**Post date:** [April 27, 2016, 7:29am UTC](https://forum.ionicframework.com/t/ion-segment-ngswitch-switch-case-only-accepts-string/50508/2 "2016-04-27T07:29:47Z")

</div>

In this case \*ngSwitchWhen="‘i’" is seek for ‘i’ char but not a 0,1,2 etc number  
Try to bind 'i" as string value  
maybe like this : can’t test now

\*ngSwitchWhen="’"+i+"’"

---

<div class="post-metadata">

**Author:** ![JosephMendez](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/josephmendez/32/99103_2.png) [@JosephMendez](https://forum.ionicframework.com/u/JosephMendez)\
**Post date:** [April 27, 2016, 10:26am UTC](https://forum.ionicframework.com/t/ion-segment-ngswitch-switch-case-only-accepts-string/50508/3 "2016-04-27T10:26:34Z")

</div>

@pivalig parse errors

```auto
        EXCEPTION: Error: Uncaught (in promise): Template parse errors:
        Unexpected closing tag "ion-list" ("
            <h2>{{itemchild.name}}</h2>
           </ion-item>
        [ERROR ->]</ion-list>
       </div>
  <!--
"): CategoryPage@64:4

```

---

<div class="post-metadata">

**Author:** ![JosephMendez](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/josephmendez/32/99103_2.png) [@JosephMendez](https://forum.ionicframework.com/u/JosephMendez)\
**Post date:** [April 27, 2016, 1:28pm UTC](https://forum.ionicframework.com/t/ion-segment-ngswitch-switch-case-only-accepts-string/50508/4 "2016-04-27T13:28:18Z")

</div>

still not working, it will only work if i assign value manually.

---

<div class="post-metadata">

**Author:** ![pivalig](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/pivalig/32/100053_2.png) [@pivalig](https://forum.ionicframework.com/u/pivalig)\
**Post date:** [April 27, 2016, 1:39pm UTC](https://forum.ionicframework.com/t/ion-segment-ngswitch-switch-case-only-accepts-string/50508/5 "2016-04-27T13:39:30Z")

</div>

Yes its like switch case. You must setup value manually

---

<div class="post-metadata">

**Author:** ![JosephMendez](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/josephmendez/32/99103_2.png) [@JosephMendez](https://forum.ionicframework.com/u/JosephMendez)\
**Post date:** [April 27, 2016, 1:46pm UTC](https://forum.ionicframework.com/t/ion-segment-ngswitch-switch-case-only-accepts-string/50508/6 "2016-04-27T13:46:54Z")

</div>

@pivalig i want to try ngShow and ngIf instead of using the ngSwitch, since i want my segments to be dynamic.

---

<div class="post-metadata">

**Author:** ![JosephMendez](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/josephmendez/32/99103_2.png) [@JosephMendez](https://forum.ionicframework.com/u/JosephMendez)\
**Post date:** [April 27, 2016, 3:45pm UTC](https://forum.ionicframework.com/t/ion-segment-ngswitch-switch-case-only-accepts-string/50508/7 "2016-04-27T15:45:45Z")

</div>

ngswitch only accepts primitive strings: so below is work around for me, using ngshow and ngmodel and hidden

```
  <div><ion-segment [(ngModel)]="selectedSegment">
     <ion-segment-button *ngFor="#item of fetchCatch; #x = index"
          (click)="showSegment(item.id)"
          [value]="item.title">
                 {{item.name}}
           </ion-segment-button>
          </ion-segment>
      </div>
      <ion-content>
     <div> 
        <ion-list *ngFor="#itemx of fetchCatch; #i = index"
        [hidden]="hideSegment(selectedSegment,itemx.id)">
     <ion-item *ngFor="#itemchild of itemx.children" (click)="categoryDetails(itemchild)">
    <h2>{{itemchild.name}}</h2>
  </ion-item>
</ion-list>

```

```
           showSegment(i){
               this.selectedSegment = i;
           }

          hideSegment(a,b){
              if(a==b)
              return true;
         }
```
