diff --git a/libs/transloco/src/lib/transloco.service.ts b/libs/transloco/src/lib/transloco.service.ts index d9db85b3..5539aafa 100644 --- a/libs/transloco/src/lib/transloco.service.ts +++ b/libs/transloco/src/lib/transloco.service.ts @@ -116,6 +116,7 @@ export class TranslocoService { }; private destroyRef = inject(DestroyRef); + private destroyed = false; constructor( @Optional() @Inject(TRANSLOCO_LOADER) private loader: TranslocoLoader, @@ -151,6 +152,7 @@ export class TranslocoService { }); this.destroyRef.onDestroy(() => { + this.destroyed = true; // Complete subjects to release observers if users forget to unsubscribe manually. // This is important in server-side rendering. this.lang.complete(); @@ -200,6 +202,13 @@ export class TranslocoService { } load(path: string, options: LoadOptions = {}): Observable { + // If the application is already destroyed, the `load` should not + // execute anything in practice because other resources have already + // been released and destroyed. + if (this.destroyed) { + return EMPTY; + } + const cached = this.cache.get(path); if (cached) { return cached;