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 Jan 23, 2024
1 parent f770c11 commit 831c1bc
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export class NgxFireworksComponent {
@Input() options?: FireworkOptions;
@Input() id: string;

container: Promise<any> | null = null;

constructor(@Inject(PLATFORM_ID) protected platformId: string) {
this.id = 'tsparticles';
}
Expand All @@ -20,6 +22,16 @@ export class NgxFireworksComponent {
return;
}

fireworks(this.id, this.options);
this.container = fireworks(this.id, this.options);
}

public ngOnDestroy(): void {
if (this.container) {
this.container.then((firework: any) => {
if (firework && typeof firework.stop === 'function') {
firework.stop();
}
});
}
}
}

0 comments on commit 831c1bc

Please sign in to comment.