Is there any way to force an option of a <mat-option> by a service?

Asked

Viewed 252 times

0

I basically have a mat-option, and would like to select an option from it directly by parameters, with a service, for example.

This is the option:

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

When I load this component it is without any option checked, but there is a feature that requires an option of this mat-option is selected, via parameter.

1 answer

0

Just have the form control with the same value as the value of your option. For example:

this.form.get('emptyTitle').setValue(this.indices[0]._id)

Browser other questions tagged

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