Skip to content

Commit 690f177

Browse files
authored
Merge pull request #90 from Eric-Guo/main
Should clean the fireworks when ngOnDestroy
2 parents a9cefd8 + 1033184 commit 690f177

File tree

2 files changed

+3174
-2936
lines changed

2 files changed

+3174
-2936
lines changed

components/fireworks/projects/ng-fireworks/src/lib/ng-fireworks.component.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { isPlatformServer } from '@angular/common';
22
import { Component, Inject, Input, PLATFORM_ID } from '@angular/core';
3-
import { FireworkOptions, fireworks } from '@tsparticles/fireworks';
3+
import { FireworkOptions, fireworks, FireworksInstance } from '@tsparticles/fireworks';
44

55
@Component({
66
selector: 'ngx-fireworks',
@@ -11,6 +11,8 @@ export class NgxFireworksComponent {
1111
@Input() options?: FireworkOptions;
1212
@Input() id: string;
1313

14+
fireworks_instance: FireworksInstance | undefined = undefined;
15+
1416
constructor(@Inject(PLATFORM_ID) protected platformId: string) {
1517
this.id = 'tsparticles';
1618
}
@@ -20,6 +22,14 @@ export class NgxFireworksComponent {
2022
return;
2123
}
2224

23-
fireworks(this.id, this.options);
25+
fireworks(this.id, this.options).then((firework: FireworksInstance | undefined) => {
26+
this.fireworks_instance = firework;
27+
});
28+
}
29+
30+
public ngOnDestroy(): void {
31+
if (this.fireworks_instance) {
32+
this.fireworks_instance.stop();
33+
}
2434
}
2535
}

0 commit comments

Comments
 (0)