I want to create a custom component on top of angular material mat-select. The custom component should support both reactive form and not a reactive form.
The custom component get inputs as:
@Input() group: FormGroup;
@Input() controlName: string;
the custom component HTML
<mat-form-field [formGroup]="group">
<mat-select placeholder="Favorite food" [formControlName]="controlName">
<mat-option *ngFor="let food of foods" [value]="food.value">
{{food.viewValue}}
</mat-option>
</mat-select>
</mat-form-field>
it works fine when I pass the group and the controlName but when I want to use the same component without reactive form I get error: "formGroup expects a FormGroup instance. Please pass one in"
<!-- With Reactive Form -->
<app-custom-dropdown [group]="form" [controlName]="'foods'"></app-custom-dropdown>
<!-- Without Reactive Form -->
<app-custom-dropdown></app-custom-dropdown>
My Question is how I can support both cases when the custom component used with reactive form and in other time without reactive form.