Skip to content

Commit

Permalink
Should clean the fireworks when ngOnDestroy
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Guo committed Feb 4, 2024
1 parent a9cefd8 commit 2e9668a
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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';
}
Expand All @@ -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();
}
}
}

0 comments on commit 2e9668a

Please sign in to comment.