On my home page (homePageComponent), I have a search feature. When the user clicks on the search button, they are redirected to a different page called the search list page (searchListComponent). Within the searchListComponent, there is another component called the search card component (searchCardComponent) where all the search results are displayed. I attempted to pass the search text from the homePageComponent to the searchCardComponent using an event emitter, but unfortunately, the data is not being passed successfully. I would greatly appreciate any assistance with this issue.
Below is a snippet of sample code:
homePageComponent
HTML (Product A)
<ng-select
class="col-md-5 solution-list-dropdown"
[items]="productType$ | async"
[addTag]="true"
[(ngModel)]="selectedSolutionId"
bindLabel="description"
bindValue="id"
placeholder="Select"
[clearable]=true
[searchable]=true
[dropdownPosition]="'down'"
[ngClass]="{ 'dropdown-is-invalid': submitted && f.category.errors }">
</ng-select>
<button class="red-button" (click)="searchRedirection(selectedSolutionId)">
Search
</button>
Typescript
@Output() searchValue = new EventEmitter<string>();
public searchRedirection(selectedSolutionId: string) {
this.searchValue.emit(selectedSolutionId);
this.router.navigate(['/category/' + selectedSolutionId]);
}
SearchListComponent
HTML
<div class="container-fluid product-card-container p-0" id="hor-divider">
<div class="product-list">
<app-product-card (searchValue)="onApplyEvent($event)" *ngFor="let product of products | filter:searchText | filter:filterText" [product]="product">
</app-product-card>
</div>
</div>
Typescript
onApplyEvent(event: any): any {
console.log('event : ' + event);
}
In this scenario, I expected the console log to print "event: Product A", so that I could use it to bind the value into *ngFor. Any guidance on resolving this issue would be highly appreciated.