Getting started
Install, provide once, then write GSAP. The Angular half is handled for you.
Install
The schematic adds gsap as a dependency and wires provideGsap() into your application config for you.
ng add ng-gsapOr do it by hand — gsap is a peer dependency and is never bundled:
npm install ng-gsap gsapimport { ApplicationConfig } from '@angular/core';
import { ScrollTrigger } from 'gsap/ScrollTrigger';
import { provideGsap } from 'ng-gsap';
export const appConfig: ApplicationConfig = {
providers: [
provideGsap({
plugins: [ScrollTrigger], // only the ones you use; the rest stay tree-shaken out
defaults: { ease: 'power2.out', duration: 0.6 },
respectReducedMotion: true,
}),
],
};Your first animation
injectGSAP runs its callback inside a gsap.context() wired to Angular's reactivity. You never list what the animation depends on — Angular tracks the signals you read, so changing one re-runs the callback with the previous run already reverted.
import { Component, ElementRef, signal, viewChild } from '@angular/core';
import { gsap } from 'gsap';
import { injectGSAP } from 'ng-gsap';
@Component({
selector: 'app-box',
template: `<div #stage><div class="box"></div></div>`,
})
export class Box {
private stage = viewChild.required<ElementRef>('stage');
protected open = signal(false);
constructor() {
injectGSAP(() => {
// `open` is read here, so this re-runs whenever it changes
gsap.to('.box', { x: this.open() ? 220 : 0 });
}, { scope: this.stage });
}
protected toggle() {
this.open.update((v) => !v);
}
}Nothing to declare, nothing to clean up. That is the entire idea — everything else in this library follows from it.
What scope does
scope confines every selector string used inside the callback to that element, so '.box' can never reach into another component. Pass a viewChild() signal and the callback waits until it resolves, then runs; an optional view child that is not on screen yet never lets a selector escape to the whole page. You can skip scope entirely if you pass real elements to GSAP instead of selector strings.
Where to go next
- API reference — every export, across the main and the three optional entry points.
- Guides — SSR, testing, route transitions, reduced motion, smooth scrolling.
- Live examples — every idea, running, with its source.