Problem with segments and checkboxs


#1

I’ve created segments options in one of my pages. The code is the following:

<div padding>
  <ion-segment [(ngModel)]="accion">
    <ion-segment-button value="crear">
      Crear zona
    </ion-segment-button>
    <ion-segment-button value="modificar">
      Modificar zona
    </ion-segment-button>
  </ion-segment>
</div>

<ion-card center *ngIf="accion=='crear'">
  <ion-card-content>

    <ion-list>
      <ion-item>
        <ion-label floating> Nombre del area: </ion-label>
        <ion-input type="text" [(ngModel)]="nombreArea"> </ion-input>
      </ion-item>
      <ion-item>
        <label>Dispositivo asociado:</label>
        <ion-list>
          <ion-item *ngFor="let dispositivo2 of dispositivosAnadir">
            <ion-label> {{dispositivo2.name}} </ion-label>
              <ion-checkbox color="royal" [(ngModel)]="dispositivo2.selected" value="dispositivo2.value"></ion-checkbox>
          </ion-item>
        </ion-list>
      </ion-item>
    </ion-list>

    <div padding>
      <button (click)="marcarTodos()" ion-button icon-left color="royal">
        <ion-icon name="checkmark-circle"></ion-icon> Marcar todos 
      </button>
      <button (click)="desmarcarTodos()" ion-button icon-left color="royal"> 
        <ion-icon name="radio-button-off"></ion-icon> Desmarcar todos 
      </button>
    </div>

    <div padding>
      <button (click)="startShape()" [disabled]="pintando" ion-button icon-left color="royal">
        <ion-icon name="brush"></ion-icon> Pintar zona
      </button>
      <button (click)="endShape()" [disabled]="!pintando" ion-button icon-left color="royal">
        <ion-icon name="flag"></ion-icon> Fin pintar zona
      </button>
      <button (click)="cancelShape()" [disabled]="!pintando" ion-button icon-left color="royal">
        <ion-icon name="close"></ion-icon> Cancelar
      </button>
    </div>

  </ion-card-content>
</ion-card>


<ion-card center *ngIf="accion=='modificar'">
  <ion-card-content>

    <ion-list>
      <ion-item>
        <ion-label>Seleccionar zona: </ion-label>
        <ion-select [(ngModel)]="zonasSelector.seleccionada" (ionChange)="cambioZonaSeleccionada()">
          <ion-option *ngFor="let zona of zonasSelector.array" [value]="zona.value">{{zona.name}}</ion-option>
        </ion-select>
      </ion-item>
      <ion-item>
        <ion-list>
          <ion-item *ngFor="let dispositivo of dispositivosModificar">
            <ion-label> {{dispositivo.name}} </ion-label>
              <ion-checkbox color="royal" [(ngModel)]="dispositivo.selected" value="dispositivo.value" [disabled]="zonasSelector.seleccionada == null"></ion-checkbox>
          </ion-item>
        </ion-list>
      </ion-item>
    </ion-list>

    <div padding>
      <button ion-button icon-left (click)="modificarZona()" [disabled]="zonasSelector.seleccionada == null" color="royal"> 
        <ion-icon name="checkmark"></ion-icon> Modificar 
      </button>
      <button ion-button icon-left (click)="showConfirmDelete()" [disabled]="zonasSelector.seleccionada == null" color="royal"> 
        <ion-icon name="trash"></ion-icon> Eliminar
      </button>
    </div>

  </ion-card-content>
</ion-card>

Before, I was showing the content without separating in segments and worked well, but when introduced it in segments I have a problem. I have on both segments a ngFor to represent a set of checkboxs. The first time the page loads, the checks are shown well but if I change the segment, don’t matter wich I choose, the checkboxs disapear. The other things I show in the segments (inputs and button) appears well.

Anyone has idea?


#2

If someone is interested I have solved it taking out the ion list with the ngFor and adding it in the ion-card-content, not inside the first ion-list.


<!-- SEGMENTOS -->
<div padding>
  <ion-segment [(ngModel)]="accion">
    <ion-segment-button value="crear">
      Crear zona
    </ion-segment-button>
    <ion-segment-button value="modificar">
      Modificar zona
    </ion-segment-button>
  </ion-segment>
</div>


<!-- CREAR ZONA -->
<ion-card center *ngIf="accion=='crear'">
  <ion-card-content>

    <ion-list>
      <ion-item>
        <ion-label floating> Nombre del area: </ion-label>
        <ion-input type="text" [(ngModel)]="nombreArea"> </ion-input>
      </ion-item>
    </ion-list>

    <div padding>
      <label>Dispositivo asociado:</label>
      <ion-list>
        <ion-item *ngFor="let dispositivo2 of dispositivosAnadir">
          <ion-label> {{dispositivo2.name}} </ion-label>
            <ion-checkbox color="royal" [(ngModel)]="dispositivo2.selected" value="dispositivo2.value"></ion-checkbox>
        </ion-item>
      </ion-list>
    </div>

    <div padding>
      <button (click)="marcarTodos()" ion-button icon-left color="royal">
        <ion-icon name="checkmark-circle"></ion-icon> Marcar todos 
      </button>
      <button (click)="desmarcarTodos()" ion-button icon-left color="royal"> 
        <ion-icon name="radio-button-off"></ion-icon> Desmarcar todos 
      </button>
    </div>

    <div padding>
      <button (click)="startShape()" [disabled]="pintando" ion-button icon-left color="royal">
        <ion-icon name="brush"></ion-icon> Pintar zona
      </button>
      <button (click)="endShape()" [disabled]="!pintando" ion-button icon-left color="royal">
        <ion-icon name="flag"></ion-icon> Fin pintar zona
      </button>
      <button (click)="cancelShape()" [disabled]="!pintando" ion-button icon-left color="royal">
        <ion-icon name="close"></ion-icon> Cancelar
      </button>
    </div>

  </ion-card-content>
</ion-card>


<!-- MODIFICAR ZONA -->
<ion-card center *ngIf="accion=='modificar'">
  <ion-card-content>

    <ion-list>
      <ion-item>
        <ion-label>Seleccionar zona: </ion-label>
        <ion-select [(ngModel)]="zonasSelector.seleccionada" (ionChange)="cambioZonaSeleccionada()">
          <ion-option *ngFor="let zona of zonasSelector.array" [value]="zona.value">{{zona.name}}</ion-option>
        </ion-select>
      </ion-item>
    </ion-list>

    <ion-list>
      <ion-item *ngFor="let dispositivo of dispositivosModificar">
        <ion-label> {{dispositivo.name}} </ion-label>
        <ion-checkbox color="royal" [(ngModel)]="dispositivo.selected" value="dispositivo.value" [disabled]="zonasSelector.seleccionada == null"></ion-checkbox>
      </ion-item>
    </ion-list>

    <div padding *ngIf="accion=='modificar'">
      <button ion-button icon-left (click)="modificarZona()" [disabled]="zonasSelector.seleccionada == null" color="royal"> 
        <ion-icon name="checkmark"></ion-icon> Modificar 
      </button>
      <button ion-button icon-left (click)="showConfirmDelete()" [disabled]="zonasSelector.seleccionada == null" color="royal"> 
        <ion-icon name="trash"></ion-icon> Eliminar
      </button>
    </div>

  </ion-card-content>
</ion-card>