Skip to content

Commit 85fbd01

Browse files
committed
Fix Service
Add timout for after change errors
1 parent bb795b1 commit 85fbd01

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

task-manager/src/app/shared/services/loader/loader.service.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { ApplicationRef, ComponentRef, inject, Injectable, ViewContainerRef } from '@angular/core';
22
import { LoaderComponent } from '../../components';
33

4-
54
@Injectable({ providedIn: 'root' })
65
export class LoaderService {
7-
86
private componentRef: ComponentRef<LoaderComponent> | null;
97
private readonly applicationRef: ApplicationRef;
108

@@ -14,17 +12,23 @@ export class LoaderService {
1412
}
1513

1614
public start(text?: string): void {
17-
const container = this.applicationRef.components[0].injector.get(ViewContainerRef);
18-
const loaderComponentRef = container.createComponent(LoaderComponent);
19-
loaderComponentRef.instance.label = text;
20-
this.componentRef = loaderComponentRef;
15+
const timeoutRef = setTimeout(() => {
16+
const container = this.applicationRef.components[0].injector.get(ViewContainerRef);
17+
const loaderComponentRef = container.createComponent(LoaderComponent);
18+
loaderComponentRef.instance.label = text;
19+
this.componentRef = loaderComponentRef;
20+
clearTimeout(timeoutRef);
21+
}, 100);
2122
}
2223

2324
public stop(): void {
24-
if (this.componentRef !== null) {
25-
this.componentRef?.destroy();
26-
this.componentRef = null;
27-
}
25+
const timeoutRef = setTimeout(() => {
26+
if (this.componentRef !== null) {
27+
this.componentRef?.destroy();
28+
this.componentRef = null;
29+
}
30+
clearTimeout(timeoutRef);
31+
}, 100);
2832
}
2933

3034
public startAndStop(fn: () => void, message?: string) {

0 commit comments

Comments
 (0)