Calling filter method Status

Asked

Viewed 60 times

0

I have this method, when choosing a country, search the states.

  filtrarEstado(pais : Pais) : void{
    this.loading = true;
    this.estadoService.getEstadosPorPais(pais).subscribe( 
      (data :any) => {
        this.estados = data.lista;
        this.loading = false;
      }
    );
  }

Component in the HTML

<mat-form-field class="formulario-full-width">
            <mat-select placeholder="País" name="pais" 
              [(ngModel)]="municipioBuscar.paisId" 
              matTooltip="Deve selecionar um país">
              <mat-option (blur)="filtrarEstado(0)">Nenhum</mat-option>
              <mat-option *ngFor="let pais of paises" [value]="pais" 
                (blur)="filtrarEstado(pais)">{{pais.descricao}}
              </mat-option>
            </mat-select>
          </mat-form-field>

But when I choose none, does not execute the method state, thus the state component is completed with the states of the last chosen country.

What’s wrong with it?

1 answer

1

Try with the change event in select

<mat-form-field class="formulario-full-width">
    <mat-select placeholder="País" name="pais" 
         [(ngModel)]="municipioBuscar.paisId" 
         matTooltip="Deve selecionar um país"
         (change)="filtrarEstado($event)">
            <mat-option>Nenhum</mat-option>
            <mat-option *ngFor="let pais of paises" [value]="pais" 
            >{{pais.descricao}}
             </mat-option>
      </mat-select
</mat-form-field>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.