1

I'm trying to use mat-select of Angular Material 11.2.12.

Since I need to make mat-select do some stuff (filter, select/deselect all) besides its default behavior, I need to put it inside a component of mine.

Something like this:

<my-component>    
    <mat-select #select [formControlName]="selectControl" multiple>  
     <my-stuff>bla bla bla</my-stuff>
      <mat-option *ngFor="let item of filteredItems" [value]="item.value">{{ item.text }}</mat-option>
    </mat-select>    
</my-component>

What should I do inside <my-component> to be able to use <my-component> inside a form, as I'm now able to use <mat-select> inside a form.

Thanks for your help

Matt
  • 265
  • 4
  • 17
  • 1
    Check https://angular.io/api/forms/ControlValueAccessor . You can refer example such as https://blog.angular-university.io/angular-custom-form-controls/ – Shashank Vivek Apr 06 '22 at 07:28
  • 1
    Does this answer your question? [Passing a FormControl to a child component - No value accessor for form control with unspecified name](https://stackoverflow.com/questions/53099559/passing-a-formcontrol-to-a-child-component-no-value-accessor-for-form-control) – Daniel B Apr 06 '22 at 07:49
  • Thanks everybody, I'll take a look :) – Matt Apr 06 '22 at 14:03
  • Thanks guys, those answers solve my problem – Matt Apr 06 '22 at 16:21

0 Answers0