重新使用屏幕进行编辑

Reuse screen to edit

我有一个带有日期字段的屏幕和一些带有框的屏幕,我需要填充它们以重新验证屏幕以进行编辑,屏幕用于注册和编辑,但是我无法将数据传递到组合框字段.银行返回的数据是期权的id。

页面代码:

    <ion-grid  *ngFor="let editar of lista_despesa_ed">

        <ion-row>
          <ion-col col-6 class="sem-espaco">
            <ion-item>
              <ion-label floating>Data</ion-label>
              <ion-datetime class="input-color" displayFormat="DD MM YYYY" pickerFormat="DD MM YYYY" [(ngModel)]="data"></ion-datetime>
            </ion-item>
            <h6 *ngIf="errorData" class="error"> {{messageData}}</h6>
          </ion-col>
        </ion-row>

        <ion-row>
          <ion-col col-12 class="sem-espaco">
            <ion-list>
              <ion-item>
                <ion-label floating>Centro de Custo</ion-label>
                <ion-select (ionChange)="resetCusto()" [(ngModel)]="custo" class="input-color">
                  <ion-option *ngFor="let custo of lista_centroCusto" [selected]="editar.IDCentroCusto" value="{{custo.Chave}}">{{custo.Valor}}
                  </ion-option> //The error occurs here
                </ion-select>
              </ion-item>
              <h6 *ngIf="errorCusto" class="error"> {{messageCusto}}</h6>
            </ion-list>
          </ion-col>
        </ion-row>

打字稿文件:

  ionViewDidEnter() {
    if (this.global.acao === "I") {
      this.carregaCB();
    } else if (this.global.acao === "E") {
      this.carregaCB();
      this.AprovacaoProvider.listaDetalhe().then((data) => {
        this.lista_despesa_ed = data;
      })
    }
  }

由于您在该组合框中使用 [(ngModel)] 并且 custo 是与其绑定的组件中的 属性,因此您只需要分配 already 的值组件文件中 custo 属性 的选定选项:

this.custo = editar.IDCentroCusto; // Not sure if this is the right property

然后在视图中:

<ion-select [(ngModel)]="custo" class="input-color">
    <ion-option *ngFor="let custo of lista_centroCusto" [value]="custo.Chave">{{custo.Valor}}</ion-option>
</ion-select>

请注意,我还建议对 value 使用 属性 绑定(而不是字符串插值),如下所示:[value]="custo.Chave".