How to give "Trigger" in an Option of a Mat-select that is already selected?

Asked

Viewed 510 times

0

I basically have this mat-select:

<mat-select [formControl]="form.get('emptyTitle')" placeholder="Nenhum Índice Selecionado"
            (selectionChange)="onSelect($event)">
            <mat-option value="">Nenhum Índice Selecionado</mat-option>
            <div *ngFor="let indice of indices">
                <mat-option [value]="indice._id">{{indice._source.titulo}}</mat-option>
            </div>
        </mat-select>

The problem is I need to call the function onSelect again, and obviously the observer (selectionChange) does not capture this selection, since it is the same.

Is there any way to recall this selection that is already selected?

1 answer

1


Well, first of all I don’t know why you want to select something that has already been selected XD but come on...

(If I understood your question) A simple solution to your problem would be to link the event click at the mat-option

<mat-select 
   [formControl]="form.get('emptyTitle')" 
   placeholder="Nenhum Índice Selecionado"
   (selectionChange)="onSelect($event)">
    <mat-option value="">Nenhum Índice Selecionado</mat-option>
    <div *ngFor="let indice of indices">
    <mat-option (click)="selectClick()" [value]="indice._id">
        {{indice._source.titulo}}
    </mat-option>
</div>

and in typescript:

selectClick() {
    let valorSelecionado = this.form.get('emptyTitle').value;
   // aqui você executa a ação
}
  • I didn’t really think about it as soon as possible I will test, but it will probably work kkkkk

  • Any questions just ask :D

  • I did that, but took the (selectionChange) not to give Rigger twice in different selections kkkk

Browser other questions tagged

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