In my application, there is a component named list where I am showcasing all the names of my customers
in a dropdown
, as illustrated below:
https://i.sstatic.net/KEmAG.png
When a particular item (i.e., customer)
is selected from the dropdown
, I would like to emit that id
to a method/function
located in another component known as display.
Code snippet for the display component:
TS file
import { Component, OnInit } from '@angular/core';
import { ContactService } from '../contacts.service';
@Component({
selector: 'app-display',
templateUrl: './display.component.html',
styleUrls: ['./display.component.css']
})
export class DisplayComponent implements OnInit {
public contacts:any;
constructor(private myService: ContactService) { }
public async ngOnInit(): Promise<void> {
this.contacts = await this.myService.getCustomersById('id');<=== Need to pass emitted customer id to here
}
}
I am currently emitting the ID from the dropdown in the list component.
However, I am facing difficulty passing the emitted id to the services file and subscribing to that id in the display component. Although I have created a services file, I am struggling to
communicate
with it.