Guides

The five things people ask about after the first animation works.

Server-side rendering

injectGSAP runs in the write phase of Angular's render lifecycle, which never executes on the server. There is no isPlatformBrowser check to write and no afterNextRender wrapper to remember.

// Nothing to configure. injectGSAP runs in the render lifecycle's
// write phase, which never executes on the server.
injectGSAP(() => {
  gsap.to('.box', { x: 220 });
}, { scope: this.stage });

This site is the proof: it is built with outputMode: "static", so every one of its pages — each example included — is rendered in Node with no DOM on every build. A checked-in script then asserts the server output contains real content and no GSAP side effects.

injectScrollTrigger and provideGsapRouteTransitions are server-safe the same way: both detect that there is no browser and stay inert instead of throwing.

Testing

ng-gsap/testing freezes GSAP so nothing moves except what you move, then lets you advance it by an exact number of milliseconds.

box.spec.ts
import { advanceGsap, provideGsapTesting } from 'ng-gsap/testing';

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

it('slides the box open', async () => {
  // Box animates '.box' with { x: 220, duration: 1, ease: 'none' } while open
  const fixture = TestBed.createComponent(Box);
  fixture.componentInstance.open.set(true);
  fixture.detectChanges();
  await fixture.whenStable(); // the render effect has run, the tween exists

  advanceGsap(500);

  expect(gsap.getProperty('.box', 'x')).toBe(110); // halfway, exactly, every run
});

Because the global timeline is paused, gsap.set() does not apply inside a frozen test — it is a zero-duration tween, and a paused timeline never renders it. Set properties directly, or drive them through an animation you advance.

Note that fake timers cannot drive GSAP, in this or any wrapper: GSAP captures a direct reference to Date.now when its module first loads, so it keeps reading real wall-clock time no matter what vi.useFakeTimers() does to the global Date. advanceGsap seeks GSAP's global timeline instead, which sidesteps the clock entirely — that is why it is exact rather than approximately right.

Route transitions

ng-gsap/router animates routed views in and out app-wide, without touching a single component.

app.config.ts
import { provideGsapRouteTransitions } from 'ng-gsap/router';

providers: [
  provideRouter(routes),
  provideGsap(),
  provideGsapRouteTransitions({
    enter: ({ element }) => gsap.from(element, { autoAlpha: 0, y: 24, duration: 0.4 }),
    leave: ({ element }) => gsap.to(element, { autoAlpha: 0, duration: 0.3 }),
  }),
]

Angular's router does not wait for animations before destroying a view, so rather than blocking navigation, leave receives a pinned clone of the outgoing element and animates that. The clone keeps its classes and inline styles; what it cannot carry over is live state — canvas contents, video position, uncommitted form input. Animate only on enter for views where that matters.

Reduced motion

provideGsap({ respectReducedMotion: true });

While the OS reports prefers-reduced-motion: reduce, animation collapses to its end state. Elements land where they belong instead of being stranded mid-from(), callbacks still fire, and ScrollTrigger still scrubs. It reacts to the setting changing mid-session and restores normal playback on teardown.

Smooth scrolling

ng-gsap ships no smooth-scroll wrapper. The wiring is short enough to own. With Lenis, a separate library that keeps the page's native scroll, ScrollTrigger needs two things: Lenis must run on GSAP's ticker so both update in the same frame, and every Lenis scroll event must call ScrollTrigger.update. Put this in your root component to enable it app-wide:

app.ts
import { afterRenderEffect } from '@angular/core';
import { gsap } from 'gsap';
import { ScrollTrigger } from 'gsap/ScrollTrigger';
import Lenis from 'lenis';

export class App {
  constructor() {
    // Render effects never run on the server, so Lenis is never constructed there.
    afterRenderEffect((onCleanup) => {
      const lenis = new Lenis();
      const stopSync = lenis.on('scroll', ScrollTrigger.update);
      const tick = (time: number) => lenis.raf(time * 1000); // ticker time is in seconds
      gsap.ticker.add(tick);
      gsap.ticker.lagSmoothing(0);

      onCleanup(() => {
        gsap.ticker.remove(tick);
        gsap.ticker.lagSmoothing(500, 33); // GSAP's defaults
        stopSync();
        lenis.destroy();
      });
    });
  }
}

Add node_modules/lenis/dist/lenis.css to the styles array in angular.json. lagSmoothing(0) stops GSAP from adjusting its clock after a long frame, which would otherwise let Lenis and ScrollTrigger drift apart. Restoring GSAP's defaults on teardown matters when Lenis lives in a single page rather than the root, as it does in the smooth scrolling example. Lenis honours prefers-reduced-motion by default, so it pairs with respectReducedMotion without extra code.

If you would rather stay inside GSAP, its own ScrollSmoother plugin ships in the gsap package. It needs a wrapper and a content element around the page instead of keeping native scroll.