Angular Modernizer
    Preparing search index...

    Transform Rule: Subscription in Lifecycle Hook

    Converts raw .subscribe() calls in lifecycle hooks to properly managed subscriptions using takeUntilDestroyed() operator from @angular/core/rxjs-interop.

    This fixes the subscription-in-lifecycle violation type detected by PresentationalComponentViolationRule.

    Runs only when the plugin config sets transformationType: 'subscription-transform'; delegates to SubscriptionTransformOrchestrator.

    // BEFORE: raw subscription in lifecycle hook
    ngOnInit() {
    this.dataService.getData().subscribe(data => this.data = data);
    }

    // AFTER: takeUntilDestroyed ensures cleanup
    private readonly destroyRef = inject(DestroyRef);

    ngOnInit() {
    this.dataService.getData()
    .pipe(takeUntilDestroyed(this.destroyRef))
    .subscribe(data => this.data = data);
    }
    • SubscriptionTransformOrchestrator
    • PresentationalComponentViolationRule

    Implements

    Index

    Constructors

    Properties

    Methods

    Constructors

    Properties

    category: "angular-architecture" = 'angular-architecture'

    Rule category for grouping.

    description: "Add takeUntilDestroyed() to raw .subscribe() calls in lifecycle hooks" = 'Add takeUntilDestroyed() to raw .subscribe() calls in lifecycle hooks'

    Rule description explaining what it does.

    id: "angular:subscription-transform" = 'angular:subscription-transform'

    Unique rule identifier (scoped to plugin).

    name: "Subscription Transform" = 'Subscription Transform'

    Human-readable rule name.

    Methods