API reference

Four exports in the main entry point, and four more across the three optional ones.

ExportEntry pointWhat it does
injectGSAPng-gsapThe core primitive: auto-tracked dependencies, scoped context, automatic revert.
provideGsapng-gsapPlugins, defaults and reduced-motion handling, once at bootstrap.
animationSignalsng-gsapMirrors playback state of a tween or timeline as readonly signals.
gsapScrubng-gsapA writable signal bound both ways to a timeline's progress.
injectScrollTriggerng-gsap/scroll-triggerScroll position as signals, with the plugin registered for you.
provideGsapRouteTransitionsng-gsap/routerEnter and leave animations for routed views, app-wide.
provideGsapTesting / advanceGsapng-gsap/testingFreeze GSAP and advance it by exact amounts in tests.

Every inject* function and signal helper takes an optional injector, needed only when you call it outside an injection context. animationSignals and gsapScrub also take killOnDestroy (default true).

injectGSAP

const { context, contextSafe } = injectGSAP(
  (ctx) => {
    gsap.to('.box', { x: this.open() ? 220 : 0 });
  },
  { scope: this.stage },   // optional; also takes { injector }
);

Returns context (a signal of the live gsap.Context, for imperative escape hatches) and contextSafe. A scope signal that has not resolved yet makes the callback wait, so a selector never escapes to the whole document; it runs as soon as the element exists.

contextSafe

The reactive callback already runs inside the context. A handler defined outside it does not, so the tweens it creates would escape cleanup. Wrap handlers that create animations — and only those.

// creates a tween → wrap it, so it joins the same context
protected spin = this.anim.contextSafe((event: MouseEvent) => {
  gsap.to(event.target, { rotate: '+=180' });
});

// only writes a signal → no wrapper needed, the callback re-runs and cleans up
protected toggle() {
  this.open.update((v) => !v);
}

Wrapping a plain signal write is a common cargo cult. It does nothing.

provideGsap

provideGsap({
  plugins: [ScrollTrigger],                        // registered once, app-wide
  defaults: { ease: 'power2.out', duration: 0.6 }, // gsap.defaults()
  respectReducedMotion: true,                      // honour the OS setting
});

The configuration is also available as the GSAP_CONFIG injection token, and the router one as GSAP_ROUTE_TRANSITIONS. Every option and handle type is exported (GsapConfig, InjectGsapOptions, GsapHandle, GsapScope, AnimationSignals, ScrollTriggerHandle, RouteTransitionContext, GsapRouteTransitionsConfig and the rest) and covered by the same SemVer promise as the functions.

animationSignals

private timeline = gsap.timeline().to('.box', { x: 200 });
protected playback = animationSignals(this.timeline);

// <progress [value]="playback.progress()"></progress>
// playback.isActive() / playback.duration() are signals too

Kills the animation on destroy by default. Pass { killOnDestroy: false } when you are mirroring an animation whose lifetime belongs to something else.

gsapScrub

private timeline = gsap.timeline({ paused: true });
protected progress = gsapScrub(this.timeline);

// <input type="range" min="0" max="1" step="0.001" [(ngModel)]="progress" />

ng-gsap/scroll-trigger

import { injectScrollTrigger } from 'ng-gsap/scroll-trigger';

protected scroll = injectScrollTrigger({
  trigger: this.section,     // element, ElementRef, or a signal of one
  start: 'top center',
  end: 'bottom center',
  pin: true,                 // the full ScrollTrigger.StaticVars surface
});

// scroll.progress() · scroll.isActive() · scroll.direction()
// scroll.instance() · scroll.isSupported

A trigger signal is waited for, then the trigger re-creates itself whenever the element changes. An animation you pass in stays yours: a re-created or destroyed trigger stops driving it but never kills it, so create it inside injectGSAP and let the context revert it.

Where ScrollTrigger cannot run — during SSR, or under jsdom, neither of which has layout to measure — the handle stays inert and isSupported is false, rather than throwing. Components that use it stay unit-testable.

ng-gsap/router

import { provideGsapRouteTransitions } from 'ng-gsap/router';

provideGsapRouteTransitions({
  // the context is { element, depth, from, to }:
  // depth 0 is the top-level outlet, 1 a view inside it, and so on;
  // from and to are the URLs being left and entered
  enter: ({ element, depth }) =>
    gsap.from(element, { autoAlpha: 0, y: depth === 0 ? 24 : 12, duration: 0.4 }),
  leave: ({ element }) => gsap.to(element, { autoAlpha: 0, duration: 0.3 }),
  skipInitialTransition: true,     // default: the first view the app renders isn't animated
  outletSelector: 'router-outlet', // default: narrow it only for sibling outlets at one level
});

The leave snapshot is removed when its animation completes, reverse-completes or is killed; an animation that is already finished when you return it removes it at once. Callbacks you set on your own animation (onComplete and friends) keep running, with their params and callbackScope intact.

ng-gsap/testing

import { advanceGsap, provideGsapTesting } from 'ng-gsap/testing';

TestBed.configureTestingModule({ providers: [provideGsapTesting()] });

const tween = gsap.to(box, { x: 100, duration: 1 });
advanceGsap(500);
expect(tween.progress()).toBe(0.5); // exactly 0.5, every run