Skip to main content

RxStrategyProvider

RxStrategyProvider is the service surface for scheduling arbitrary work against the render strategies. It is CDK-exclusive: there is no native Angular equivalent for priority-aware, frame-budgeted scheduling, so it stays a supported API. Its scheduling methods (schedule, scheduleWith) are current; only the zone-era change-detection methods (scheduleCD, patchZone) are legacy and marked inline below.

For the mental model behind concurrent scheduling (frame budget, render deadlines, and the RAIL targets these APIs serve), see Concurrent scheduling & the frame budget.

Import path

import { RxStrategyProvider } from '@rx-angular/cdk/render-strategies';

Signature

@Injectable({ providedIn: 'root' })
export class RxStrategyProvider<T extends string = string> {
get config(): Required<RxRenderStrategiesConfig<T>>;

get strategies(): RxStrategies<T>;
get strategyNames(): string[];

get primaryStrategy(): RxStrategyNames<T>;
set primaryStrategy(strategyName: RxStrategyNames<T>);

readonly primaryStrategy$: Observable<RxStrategyCredentials>;
readonly strategies$: Observable<RxStrategies<T>>;
readonly strategyNames$: Observable<string[]>;

schedule<R>(work: () => R, options?: ScheduleOnStrategyOptions): Observable<R>;

scheduleWith<R>(work: (v?: R) => void, options?: ScheduleOnStrategyOptions): MonoTypeOperatorFunction<R>;

scheduleCD(
cdRef: ChangeDetectorRef,
options?: ScheduleOnStrategyOptions & {
afterCD?: () => void;
abortCtrl?: AbortController;
},
): AbortController;
}

ScheduleOnStrategyOptions is { scope?: object; strategy?: string; patchZone?: false | NgZone }.

Accessors

get config()

Returns the resolved configuration in use, of type Required<RxRenderStrategiesConfig<T>>. It contains primaryStrategy, the customStrategies map, and patchZone.

const config = strategyProvider.config;

get strategies() / strategyNames

strategies returns the RxStrategies<T> map: key-value pairs of strategy name to its RxStrategyCredentials. strategyNames returns just the array of names.

const strategies = strategyProvider.strategies; // credentials map
const names = strategyProvider.strategyNames; // string[]

get primaryStrategy() / set primaryStrategy()

Reads or sets the default strategy the service uses when a call does not name one.

strategyProvider.primaryStrategy = 'low';
const current = strategyProvider.primaryStrategy;

primaryStrategy$ / strategies$ / strategyNames$

Observable forms of the accessors above. Note the split: strategies$ emits the credentials map (RxStrategies<T>), while strategyNames$ emits the array of names (string[]). primaryStrategy$ emits the current primary strategy's RxStrategyCredentials.

const strategies$ = strategyProvider.strategies$; // Observable<RxStrategies<T>>
const strategyNames$ = strategyProvider.strategyNames$; // Observable<string[]>

Scheduling methods

schedule & scheduleWith

The current, supported scheduling surface. Both take the work to run plus an optional ScheduleOnStrategyOptions.

  • schedule returns an Observable<R>; subscribe to run the work.
  • scheduleWith returns a MonoTypeOperatorFunction<R> for use inside an RxJS pipe().

The options let you pick a strategy, opt out of zone patching (patchZone: false), and set a scope. Setting scope to this coalesces multiple scheduled change-detection calls into a single cycle.

strategyProvider.schedule(() => myWork(), { strategy: 'idle', patchZone: false, scope: this }).subscribe();

source$.pipe(strategyProvider.scheduleWith(() => myWork(), { strategy: 'idle', scope: this })).subscribe();

scheduleCD & zone patching

Legacy guidance

Legacy guidance — since Angular v21, change detection is zoneless by default and Zone.js is dropped from the default bundle. This page documents a legacy approach; Angular <21 / still-zoneful / perf-retrofit may still need it. For new work, prefer the modern approach. See Zoneless & how Zone.js affected change detection for the full picture.

scheduleCD schedules an imperative change-detection cycle on a supplied ChangeDetectorRef, and the patchZone option controls whether scheduled work re-enters NgZone. Both belong to the Zone.js era. Under zoneless change detection (default since Angular v21) patchZone is a no-op, and the manual-CD need that scheduleCD served is usually covered by signals and afterNextRender. See Zoneless & how Zone.js affected change detection.

scheduleCD takes the target ChangeDetectorRef and an options object that may add afterCD (work to run after the cycle) and abortCtrl (an AbortController to cancel the scheduled cycle). It returns the AbortController.

const abort = strategyProvider.scheduleCD(this.cdRef, { afterCD: () => finalize() });
// later
abort.abort();

See also