You should avoid mixing jQuery and Angular when possible. In your case, what you are trying to achieve doesn't justify the use of jQuery.
Instead of showing your modal with jQuery in your service, you should implement a show/hide mechanism in your modal component. The easiest way is with *ngIf
but if you're looking for a cleaner way, I suggest you use Overlay
from Angular CDK
Then show your modal in your service's subscription into the modal component.
That said, your problem with StackBlitz comes from the line providers: [AppService]
missing from your modal's @Component
annotation.
Edit :
This configuration doesn't work because a service is instantiated for each component, thus you cannot emit events from one component to another. You should remove the providers: [AppService]
from every component.
Edit :
Your StackBlitz actually fails because you put a comment into JSON configuration in modal.component.ts
file (Can comments be used in JSON?).
Working StackBlitz : https://stackblitz.com/edit/angular-peugm6