Ion-toggle does not receive value at view entry


#1

Hello, I have an ion-toggle component that is bound to an object through the [(ngModel)] but even the endpoint looking for the paca value to load the object the component does not get the property value. Here is the code:

Service (Endpoint) method

atualizaRealizacaoEntrega() : Observable<boolean>{
      return this.http.put<boolean>(`${CONF_API.baseUrl}/vendedores/vendedor/realizaentrega`,null);
}

View method to call

atualizaRealizacaoEntrega(){
    this.vendedorService.atualizaRealizacaoEntrega().subscribe(response=>{
    }, error=>{
      console.log(error);
    })
  }

Loading the object into the view entry:

ionViewDidEnter() {
    this.auxiliarService.prepararJanela();
    this.authService.validarUsuario();
    this.carregarVendedor();
  }

I made a test with console.log () to know if the object was actually loading in the view entry, the object is loading normally.

The component in view:

          <ion-card-content>
              <ion-item>
                  <ion-label>Faz entrega?</ion-label>
                  <ion-toggle [(ngModel)]="vendedor.fazEntrega" (ionChange)="atualizaRealizacaoEntrega()"></ion-toggle>
              </ion-item>
          </ion-card-content>

The method atualizaRealizacaoEntrega() is working perfectly by making the property change in the backend.

carregarVendedor() method with console.log():

 carregarVendedor(){
    this.vendedorService.carregarTotemVendedor().subscribe(response=>{
      this.vendedor = response;
      console.log(this.vendedor)
    }, error =>{
      console.log(error);
    })
  }

How do I get the view to show the correct value on the ion-toggle when I enter the view and the method to load the object?


#2

Encountering the problem, the field of the object I bring by the end-of-point was not the memos behind not DTO that acquires the values, made a correction and operated normally.

The end-point uses “realizaEntrega” and the DTO was using “fazEntrega”

export interface VendedorTotemDTO {
...
    realizaEntrega: boolean;
   ...
}