diff --git a/components/fireworks/projects/ng-fireworks/src/lib/ng-fireworks.component.ts b/components/fireworks/projects/ng-fireworks/src/lib/ng-fireworks.component.ts index 0c58257..059d60c 100644 --- a/components/fireworks/projects/ng-fireworks/src/lib/ng-fireworks.component.ts +++ b/components/fireworks/projects/ng-fireworks/src/lib/ng-fireworks.component.ts @@ -1,6 +1,6 @@ import { isPlatformServer } from '@angular/common'; import { Component, Inject, Input, PLATFORM_ID } from '@angular/core'; -import { FireworkOptions, fireworks } from '@tsparticles/fireworks'; +import { FireworkOptions, fireworks, FireworksInstance } from '@tsparticles/fireworks'; @Component({ selector: 'ngx-fireworks', @@ -11,6 +11,8 @@ export class NgxFireworksComponent { @Input() options?: FireworkOptions; @Input() id: string; + fireworks_instance: FireworksInstance | null = null; + constructor(@Inject(PLATFORM_ID) protected platformId: string) { this.id = 'tsparticles'; } @@ -20,6 +22,14 @@ export class NgxFireworksComponent { return; } - fireworks(this.id, this.options); + fireworks(this.id, this.options).then((firework: FireworksInstance) => { + this.fireworks_instance = firework; + }); + } + + public ngOnDestroy(): void { + if (this.fireworks_instance) { + this.fireworks_instance.stop(); + } } }