I need alerts (error messages) from child components to appear only on parent component, but these child components might be the only/main component on another page and need to show error messages themselves.
I am new to Angular and I am having some troubles. I have looked it up but I couldn´t find a answer for my requirements.
Using Observable and Subject I have a service injected in the components to share the error messages and an component to show them. Like mentioned in this link: https://stackoverflow.com/a/47441188
If I add 'app-error-msg' to both, parent and child components, the messages will appear on both components. I could put it only in the parent component, but I still want the messages in the child/crud components in case I use them as the main component in another page.
I am using Angular 7.
List/Select Component
<app-error-msg></app-error-msg>
<div>
<!-- List and select components -->
</div
<app-crud-1 *ngIf="crud-1"></app-crud-1>
<app-crud-2 *ngIf="crud-2"></app-crud-2>
<app-crud-3 *ngIf="crud-3"></app-crud-3>
Crud Component
<app-error-msg></app-error-msg>
<form>
<!-- Form Components -->
</form>
So, I would like to have one error message service, and make the messages appear on the main component of the page. Considering a child component in one page could be a parent/main component in another page. How can achieve it? Keeping the error msg service or not... What's the best way to do it?
Thank you.