Pass object by (ngModelChange) Angular 6

0

As I could pass my object "item" that is in the for "mat-option" to the directive (ngModelChange), I need to be able to have this object in my "onChangeService" function, the only thing that happened to happen that way the value of [value].

I share the code.

<mat-form-field class="example-full-width">
  <mat-select placeholder="Servicios" formControlName="codServicio" (ngModelChange)="onChangeServicio($event)">
    <mat-option *ngFor="let item of dataServicio" [value]="item.id">
      {{item.id + ' - ' + item.name}}
    </mat-option>
  </mat-select>
  <mat-error *ngIf="formGrupNewRequerimiento.get('codServicio').hasError('min')">
    Campo Obligatorio
  </mat-error>
</mat-form-field>

I appreciate any suggestions.

    
asked by configbug 10.08.2018 в 01:01
source

1 answer

0

(ngModelChange) passes to the function that indicated an object $event with the value of [value] that has the option selected.

A quick response may be to change the [value] to contain the item complete:

...
<mat-select placeholder="Servicios" formControlName="codServicio" (ngModelChange)="onChangeServicio($event)">
   <mat-option *ngFor="let item of dataServicio" [value]="item">
     {{item.id + ' - ' + item.name}}
   </mat-option>
</mat-select>
...
    
answered by 14.08.2018 в 08:27