I have search feature in home page(homePageComponent) and when i click on search it will redirect to different page called search list page(searchListComponent) and i have one more component in searchListComponent itself(according to application design) which is called search card component(searchCardComponent) where i show all the search result. i was trying to send search text from homePageComponent to searchCardComponent using eventemitter but somehow the data is not passing. it would be good if somebody help on that.
Sample code below
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);
}
Here i'm expecting the console log to print the "event : Product A", so that i can leverage it to bind this value into *ngFor. Any help would be appreciated.