You can use the EventEmitter and @Output() to achieve your goal.
Dropdown menu component:
import { Component, Output, EventEmitter, NgModule } from '@angular/core';
@Component({
selector: 'app-dropdown',
template: `
<div>
<select [(ngModel)]="selected" (ngModelChange)="onChange($event)">
<option *ngFor="let category of categories" [value]="category">{{category}}</option>
</select>
</div>`
})
export class DropdownComponent {
@Output() selectedCategory: EventEmitter<string> = new EventEmitter<string>();
categories = ["All categories", "A", "B", "C"]; //your categories list
selected: string = "All categories"; //default value
constructor() {
}
onChange(newvalue): void {
this.selectedCategory.emit(newvalue);
}
}
Here is the other component that will receive the selected value whenever it changes from the dropdown component
import {Component, NgModule} from '@angular/core'
@Component({
selector: 'app-main',
template: `
<div>
<app-dropdown (selectedCategory)='onChange($event)'></app-dropdown>
</div>
`,
})
export class MainComponent {
selected: string;
constructor() {
}
onChange(category):void {
this.selected = category;
//get your items list based on the selected category
}
}