Is there a way for parent components to communicate with child components by injecting providers directly into the TypeScript file of each child component? I am trying to retrieve data using get and set methods, but I am unsure how to proceed. Any suggestions?
Service
export class ProductSharingDataService {
public productName!: any;
constructor() { }
setRowName(selectedTableRowData: any){
this.productName = selectedTableRowData;
}
getRowName(): string {
return this.productName;
}
}
components.ts
@Component({
selector: 'app-product-page',
templateUrl: './product-page.component.html',
styleUrls: ['./product-page.component.css'],
providers: [ProductSharingDataService] // Service injected here
})
export class ProductPageComponent {
public selectedArrayParent!: Product;
constructor(private productSharingDataService:
ProductSharingDataService) {
this.productSharingDataService.getRowName();
}
receive($event: any) {
this.selectedArrayParent = $event;
// Trying to extract data from $event
}
}