diff --git a/npm/ng-packs/packages/core/src/lib/directives/permission.directive.ts b/npm/ng-packs/packages/core/src/lib/directives/permission.directive.ts index 1d83d1275e..fda8b7d315 100644 --- a/npm/ng-packs/packages/core/src/lib/directives/permission.directive.ts +++ b/npm/ng-packs/packages/core/src/lib/directives/permission.directive.ts @@ -60,7 +60,7 @@ export class PermissionDirective implements OnInit, OnDestroy, OnChanges { } ngOnDestroy(): void { - this.subscription.unsubscribe(); + if (this.subscription) this.subscription.unsubscribe(); } ngOnChanges({ condition }: SimpleChanges) { diff --git a/npm/ng-packs/packages/core/src/lib/directives/stop-propagation.directive.ts b/npm/ng-packs/packages/core/src/lib/directives/stop-propagation.directive.ts index 4faf900232..12c035cc19 100644 --- a/npm/ng-packs/packages/core/src/lib/directives/stop-propagation.directive.ts +++ b/npm/ng-packs/packages/core/src/lib/directives/stop-propagation.directive.ts @@ -13,14 +13,9 @@ export class StopPropagationDirective implements OnInit { constructor(private el: ElementRef, private subscription: SubscriptionService) {} ngOnInit(): void { - const click$ = this.subscription.addOne( - fromEvent(this.el.nativeElement, 'click'), - (event: MouseEvent) => { - event.stopPropagation(); - this.stopPropEvent.emit(event); - }, - ); + this.subscription.addOne(fromEvent(this.el.nativeElement, 'click'), (event: MouseEvent) => { + event.stopPropagation(); + this.stopPropEvent.emit(event); + }); } - - ngOnDestroy(): void {} } diff --git a/npm/ng-packs/packages/theme-shared/src/lib/components/loader-bar/loader-bar.component.ts b/npm/ng-packs/packages/theme-shared/src/lib/components/loader-bar/loader-bar.component.ts index 8ed30f2cbb..f94b6b3656 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/components/loader-bar/loader-bar.component.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/components/loader-bar/loader-bar.component.ts @@ -21,6 +21,7 @@ import { filter } from 'rxjs/operators'; `, styleUrls: ['./loader-bar.component.scss'], + providers: [SubscriptionService], }) export class LoaderBarComponent implements OnDestroy, OnInit { protected _isLoading: boolean; diff --git a/npm/ng-packs/packages/theme-shared/src/lib/tests/loader-bar.component.spec.ts b/npm/ng-packs/packages/theme-shared/src/lib/tests/loader-bar.component.spec.ts index e363dacfd1..a369c97b37 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/tests/loader-bar.component.spec.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/tests/loader-bar.component.spec.ts @@ -1,9 +1,15 @@ -import { Router, RouteReuseStrategy, NavigationStart, NavigationEnd, NavigationError } from '@angular/router'; +import { + Router, + RouteReuseStrategy, + NavigationStart, + NavigationEnd, + NavigationError, +} from '@angular/router'; import { createHostFactory, SpectatorHost, SpyObject } from '@ngneat/spectator/jest'; import { Actions, NgxsModule, Store } from '@ngxs/store'; import { Subject, Subscription, Observable, Subscriber, timer } from 'rxjs'; import { LoaderBarComponent } from '../components/loader-bar/loader-bar.component'; -import { StartLoader, StopLoader } from '@abp/ng.core'; +import { StartLoader, StopLoader, SubscriptionService } from '@abp/ng.core'; import { HttpRequest } from '@angular/common/http'; describe('LoaderBarComponent', () => { @@ -16,6 +22,7 @@ describe('LoaderBarComponent', () => { mocks: [Router], imports: [NgxsModule.forRoot()], detectChanges: false, + providers: [SubscriptionService], }); beforeEach(() => {