Picture a scenario where we have 3 components, and one of them contains a function that I need to access in the other components. These components are all at the same level (siblings).
file1.ts
export class ComponentWithFunction() {
function getData() {
console.log('data has been fetched');
}
}
file2.ts
export class ComponentA() {
// here I want to be able to utilize getData
}
file3.ts
export class ComponentB() {
// here I want to be able to utilize getData
}
How can I access the getData function from another component? I am aware that I could create a SharedService and Inject it into the specified components, but is there an alternative method such as using static functions or something similar?
Appreciate your help