Calling filtering method

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 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 , it does not execute the filterState method, so the state component is populated with states from the last chosen country.

What's wrong?

    
asked by anonymous 22.05.2018 / 16:02

1 answer

1

Try with 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>
    
22.05.2018 / 17:09