Skip to content

Commit

Permalink
Merge pull request #90 from Eric-Guo/main
Browse files Browse the repository at this point in the history
Should clean the fireworks when ngOnDestroy
  • Loading branch information
matteobruni authored Mar 8, 2024
2 parents a9cefd8 + 1033184 commit 690f177
Show file tree
Hide file tree
Showing 2 changed files with 3,174 additions and 2,936 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 | undefined = undefined;

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 | undefined) => {
this.fireworks_instance = firework;
});
}

public ngOnDestroy(): void {
if (this.fireworks_instance) {
this.fireworks_instance.stop();
}
}
}
Loading

0 comments on commit 690f177

Please sign in to comment.