离子2段,内容消失



我在我的一个页面中创建了区段选项。代码如下:

<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>
以前,我

展示内容而不分段,效果很好,但是当分段介绍时,我遇到了问题。问题是在这两个段上,我都有一个 ngFor 来表示一组复选框,并且页面第一次加载时,检查显示得很好,但是如果我更改段,无论我选择哪个,复选框都会消失。

有人知道吗?

如果有人感兴趣,我已经解决了它,用ngFor取出离子列表并将其添加到离子卡内容中,而不是在第一个离子列表中。

<!-- 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>

相关内容

  • 没有找到相关文章