Skip to content

Open source · MIT

Delete the boilerplate. Keep the Angular.

ngxtension is a collection of 70+ small utilities for signals, the router, forms, RxJS and the DOM. Each one is its own entry point, so you only ship what you import.

Same component. Fewer lines.

Three jobs every Angular app has, first in plain Angular, then with ngxtension. Watch each one shrink, or flip it yourself.

Keep the search box in the URL

Instead of reading ActivatedRoute and calling the router by hand, linkedQueryParam gives you a signal that writes to the URL, and a URL that writes to the signal.

Read the linkedQueryParam docs
export class SearchPage {
  private route = inject(ActivatedRoute);
  private router = inject(Router);

  search = toSignal(
    this.route.queryParamMap.pipe(
      map((params) => params.get('search')),
    ),
  );

  setSearch(search: string) {
    this.router.navigate([], {
      relativeTo: this.route,
      queryParams: { search },
      queryParamsHandling: 'merge',
    });
  }
}
export class SearchPage {
  search = linkedQueryParam('search');
}

Listen to window events without leaks

onEvent adds the listener and removes it when the component is destroyed, with the same AbortController you would write yourself.

Read the onEvent docs
constructor() {
  const controller = new AbortController();
  inject(DestroyRef).onDestroy(() =>
    controller.abort(),
  );

  window.addEventListener(
    'resize',
    (event) => {
      console.log('Window resized', event);
    },
    { signal: controller.signal },
  );
}
constructor() {
  onEvent(window, 'resize', (event) => {
    console.log('Window resized', event);
  });
}

Keep a setting in localStorage

injectLocalStorage reads the stored value, writes every change back, and follows other tabs through the storage event. What you get is a plain WritableSignal.

Read the injectLocalStorage docs
export class ThemeToggle {
  readonly theme = signal<'light' | 'dark'>(
    JSON.parse(
      localStorage.getItem('theme') ?? '"light"',
    ),
  );

  constructor() {
    effect(() => {
      localStorage.setItem(
        'theme',
        JSON.stringify(this.theme()),
      );
    });

    fromEvent<StorageEvent>(window, 'storage')
      .pipe(takeUntilDestroyed())
      .subscribe((e) => {
        if (e.key === 'theme' && e.newValue) {
          this.theme.set(JSON.parse(e.newValue));
        }
      });
  }
}
export class ThemeToggle {
  readonly theme = injectLocalStorage<
    'light' | 'dark'
  >('theme', {
    defaultValue: 'light',
  });
}

Every utility, by chapter

74 utilities in 12 chapters. Search by the problem you have, or browse.

Try
  • computedPrevious Signal Primitives The previous value of any signal. import { computedPrevious } from 'ngxtension/computed-previous';
  • createNotifier Signal Primitives Trigger re-computation by hand. import { createNotifier } from 'ngxtension/create-notifier';
  • createSignal / createComputed Signal Primitives Signals with a plain .value property. import { createComputed, createSignal } from 'ngxtension/create-signal';
  • extendedComputed Signal Primitives computed that receives its previous value. import { extendedComputed } from 'ngxtension/extended-computed';
  • signalHistory Signal Primitives History with undo and redo for a signal. import { signalHistory } from 'ngxtension/signal-history';
  • SignalMap Signal Primitives A Map with per-key reactivity. import { SignalMap } from 'ngxtension/collections';
  • SignalSet Signal Primitives A Set that signals track. import { SignalSet } from 'ngxtension/collections';
  • signalSlice Signal Primitives Declarative slices of state with actions. import { signalSlice } from 'ngxtension/signal-slice';
  • toLazySignal Signal Primitives toSignal that subscribes on first read. import { toLazySignal } from 'ngxtension/to-lazy-signal';
  • connect Signal Async Feed an Observable into a signal, unsubscribed on destroy. import { connect } from 'ngxtension/connect';
  • derivedAsync Signal Async computed for Promises and Observables. import { derivedAsync } from 'ngxtension/derived-async';
  • derivedFrom Signal Async combineLatest for signals and Observables. import { derivedFrom } from 'ngxtension/derived-from';
  • mergeFrom Signal Async merge for signals and Observables. import { mergeFrom } from 'ngxtension/merge-from';
  • toObservableSignal Signal Async One value you can read as a signal and subscribe to. import { toObservableSignal } from 'ngxtension/to-observable-signal';
  • createEffect Effects & Side Effects NgRx ComponentStore effects, standalone. import { createEffect } from 'ngxtension/create-effect';
  • effectOnceIf Effects & Side Effects Run an effect once, when a condition is met. import { effectOnceIf } from 'ngxtension/effect-once-if';
  • explicitEffect Effects & Side Effects An effect that only tracks the signals you list. import { explicitEffect } from 'ngxtension/explicit-effect';
  • injectAutoEffect Effects & Side Effects An effect wired to its injector, usable anywhere. import { injectAutoEffect } from 'ngxtension/auto-effect';
  • on Effects & Side Effects Explicit dependencies inside effect(). import { on } from 'ngxtension/reactive-on';
  • rxEffect Effects & Side Effects An RxJS side effect that cleans itself up. import { rxEffect } from 'ngxtension/rx-effect';
  • hostBinding Component Utilities A signal bound to a host property. import { hostBinding } from 'ngxtension/host-binding';
  • injectAttribute Component Utilities Read host attributes with inject(). import { injectAttribute } from 'ngxtension/inject-attribute';
  • injectInputs Component Utilities All signal inputs as one object signal. import { inputs } from 'ngxtension/inject-inputs';
  • mergeInputs Component Utilities Merge partial object inputs with defaults. import { mergeInputs } from 'ngxtension/inject-inputs';
  • injectLeafActivatedRoute Router The deepest active route, always current. import { injectLeafActivatedRoute } from 'ngxtension/inject-leaf-activated-route';
  • injectNavigationEnd Router An Observable of finished navigations. import { injectNavigationEnd } from 'ngxtension/navigation-end';
  • injectParams Router Route params as a signal. import { injectParams } from 'ngxtension/inject-params';
  • injectQueryParams Router Query params as a signal. import { injectQueryParams } from 'ngxtension/inject-query-params';
  • injectRouteData Router Route data as a signal. import { injectRouteData } from 'ngxtension/inject-route-data';
  • injectRouteFragment Router The URL fragment as a signal. import { injectRouteFragment } from 'ngxtension/inject-route-fragment';
  • linkedQueryParam Router A writable signal synced with a query param. import { linkedQueryParam } from 'ngxtension/linked-query-param';
  • formEvents Forms Every form event as an Observable or signal. import { allEventsSignal } from 'ngxtension/form-events';
  • ifValidator / ifAsyncValidator Forms Validators that apply only when a condition holds. import { ifValidator } from 'ngxtension/if-validator';
  • NgxControlError Forms Show control errors without the boilerplate. import { NgxControlError } from 'ngxtension/control-error';
  • NgxControlValueAccessor Forms Custom form controls in a few lines. import { NgxControlValueAccessor } from 'ngxtension/control-value-accessor';
  • notPattern Forms Valid only when the value does not match. import { notPattern } from 'ngxtension/not-pattern';
  • injectActiveElement DOM & Events Know which element has focus. import { injectActiveElement } from 'ngxtension/active-element';
  • clickOutside DOM & Events React to clicks outside an element. import { ClickOutside } from 'ngxtension/click-outside';
  • Gestures DOM & Events Drag, pinch, scroll and more, for Angular.
  • Gesture DOM & Events How to bind gestures to elements. import { NgxDrag } from 'ngxtension/gestures';
  • onEvent DOM & Events Event listeners that clean up after themselves. import { onEvent } from 'ngxtension/on-event';
  • resize DOM & Events Observe size changes of an element. import { NgxResize } from 'ngxtension/resize';
  • injectDocumentVisibility Browser APIs Whether the tab is visible, as a signal. import { injectDocumentVisibility } from 'ngxtension/inject-document-visibility';
  • injectIsIntersecting Browser APIs Know when an element enters the viewport. import { injectIsIntersecting } from 'ngxtension/inject-is-intersecting';
  • injectLocalStorage Browser APIs localStorage as a writable signal. import { injectLocalStorage } from 'ngxtension/inject-local-storage';
  • injectNetwork Browser APIs Online state and connection type. import { injectNetwork } from 'ngxtension/inject-network';
  • injectTextSelection Browser APIs The user’s text selection, as signals. import { injectTextSelection } from 'ngxtension/inject-text-selection';
  • createRepeat RxJS Operators repeat you can trigger with .emit(). import { createRepeat } from 'ngxtension/create-repeat';
  • debug RxJS Operators Log every event of a stream, tagged. import { debug } from 'ngxtension/debug';
  • deriveLoading RxJS Operators A loading flag that doesn’t flicker. import { deriveLoading } from 'ngxtension/derive-loading';
  • filterArray RxJS Operators Array.filter on emitted arrays. import { filterArray } from 'ngxtension/filter-array';
  • filterNil RxJS Operators Drop null and undefined. import { filterNil } from 'ngxtension/filter-nil';
  • mapArray RxJS Operators Array.map on emitted arrays. import { mapArray } from 'ngxtension/map-array';
  • mapSkipUndefined RxJS Operators map that skips undefined results. import { mapSkipUndefined } from 'ngxtension/map-skip-undefined';
  • poll RxJS Operators Poll a source at a fixed interval. import { poll } from 'ngxtension/poll';
  • reduceArray RxJS Operators Array.reduce on emitted arrays. import { reduceArray } from 'ngxtension/reduce-array';
  • takeLatestFrom RxJS Operators withLatestFrom that waits for every source. import { takeLatestFrom } from 'ngxtension/take-latest-from';
  • whenDocumentVisible RxJS Operators Pause a stream while the tab is hidden. import { whenDocumentVisible } from 'ngxtension/when-document-visible';
  • CallPipe / ApplyPipe Directives & Templates Call pure functions from templates, memoized. import { ApplyPipe, CallPipe } from 'ngxtension/call-apply';
  • repeat Directives & Templates Render a template N times. import { Repeat } from 'ngxtension/repeat';
  • RepeatPipe Directives & Templates Loop N times with @for. import { RepeatPipe } from 'ngxtension/repeat-pipe';
  • Svg Sprites Directives & Templates Render symbols from SVG sprites. import { NgxSvgSpriteFragment } from 'ngxtension/svg-sprite';
  • TrackById / TrackByProp Directives & Templates trackBy by id or any property. import { TrackById } from 'ngxtension/trackby-id-prop';
  • assertInjector Dependency Injection Run code in an injection context, or fail clearly. import { assertInjector } from 'ngxtension/assert-injector';
  • createInjectable Dependency Injection Services from plain functions. import { createInjectable } from 'ngxtension/create-injectable';
  • createInjectionToken Dependency Injection A token with its inject and provide functions. import { createInjectionToken } from 'ngxtension/create-injection-token';
  • createSingletonProxy Dependency Injection A singleton created on first use. import { createSingletonProxy } from 'ngxtension/singleton-proxy';
  • injectDestroy Dependency Injection A destroy$ you never have to complete. import { injectDestroy } from 'ngxtension/inject-destroy';
  • injectLazy Dependency Injection Lazy-load a service when you need it. import { injectLazy } from 'ngxtension/inject-lazy';
  • mergeHttpContext HTTP Combine several HttpContexts into one. import { mergeHttpContext } from 'ngxtension/merge-http-context';
  • Intl Internationalization Pipes for dates, numbers, lists and more. import { DisplayNamesPipe, ListFormatPipe, RelativeTimeFormatPipe } from 'ngxtension/intl';
  • Testing Utilities Testing Helpers for component and DOM tests. import { act, expectText, waitFor } from 'ngxtension/testing';
  • Host Binding Migration Migrations Move @HostBinding and @HostListener to host.
  • SFC components migration Migrations Move templates and styles inline.

Signal Primitives

computedPrevious

The previous value of any signal.

import { computedPrevious }
from 'ngxtension/computed-previous';
Read the docs

74 utilities

↑↓ move ↵ open esc clear / search

Signal Primitives

Signals that remember, undo, slice and collect.

9 utilities

Signal Async

Observables, Promises and signals, working together.

5 utilities

Effects & Side Effects

Effects with explicit dependencies and clean teardown.

6 utilities

Component Utilities

Host bindings, attributes and inputs as signals.

4 utilities

Router

Params, query params and route data as signals.

7 utilities

Forms

Validators, errors and custom controls with less boilerplate.

5 utilities

DOM & Events

Clicks, resizes, focus and gestures, cleaned up for you.

6 utilities

Browser APIs

Visibility, network, storage and intersection as signals.

5 utilities

RxJS Operators

Small operators for everyday streams.

11 utilities

Directives & Templates

Pipes and directives that keep templates short.

5 utilities

Dependency Injection

Tokens, lazy services and injection-context helpers.

6 utilities

More

HTTP, internationalization, testing and migrations.

5 utilities

Start with one import.

Add it to the app you already have. Pick one utility, import it, and delete the code it replaces.