- Within my Angular application, I have Service S that is responsible for opening Component C MatDialog;
- I am aiming for C to include a reusable header component called Component H;
- My goal is for H to feature a button that can close the MatDialog within C;
My initial attempts included:
- Trying to keep MatDialogRef as a property of S, allowing me to import it from H and call its close method. However, this led to a circular dependency issue (S -> C -> H -> S) and tightly coupled H with the S -> C structure.
- Exploring emitting an event using @Output() from H to C in order to decouple H. Yet, this approach still prevented me from injecting the service into C due to a circular dependency problem (S -> C -> S).
It seems like my current approach may be flawed. Is there a standard method to achieve this without encountering a circular dependency, while also ensuring that H remains detached from C?