In order to achieve my objective of incorporating a search form with multiple filters on any given page, I aim to implement the following structure on my HomePageComponent:
<app-search-form>
<app-searchbox></app-searchbox>
</app-search-form>
Currently, my SearchFormComponent implementation is as follows:
<form [formGroup]="form" (ngSubmit)="search()">
<ng-content></ng-content>
<br />
<button type="submit">Search</button>
</form>
SearchboxComponent details:
<label for="searchbox">Search:</label>
<input id="searchbox" formControlName="searchbox" type="text" />
For further enhancements, components like SearchCategoryFilterComponent and SearchLocationFilterComponent can be added within the <app-search-form>
as needed.
However, I encounter an error with the current setup:
NullInjectorError: NullInjectorError: No provider for ControlContainer!
This issue arises because when <app-searchbox></app-searchbox>
is inserted in HomePageComponent, it perceives HomePageComponent rather than the SearchFormComponent as the parent, resulting in the inability to inject the ControlContainer. Moving <app-searchbox></app-searchbox>
within the <form>
section of SearchFormComponent resolves the problem and ensures proper functioning of the form submission.
How can I configure this setup to allow HomePageComponent to define the content of the form? This approach not only facilitates the addition of various filters on each page but also enables customization of filter styles for individual pages.