Reference
The whole API
Everything @angular-gsap/core exports. A small surface: the library owns lifecycle, GSAP owns animation.
injectGsap(callback?, options?)
Runs the callback's GSAP code in a gsap.context() tied to the component. It runs after the first render, re-runs when signals read inside it change (reverting the previous cycle first), reverts everything on destroy, and never runs on the server.
const ref = injectGsap(({ gsap, context }) => {
// vanilla GSAP here
}, {
scope: hostElement, // optional
reactive: true, // optional
injector: injector, // optional
});Options
| Option | Default | What it does |
|---|---|---|
scope | host element | Where selector text resolves. Pass an Element, ElementRef, or CSS string to change it, or false for document-wide. |
reactive | true | Set to false to run exactly once and ignore signal changes. |
injector | current | Needed when calling outside an injection context. |
Returns GsapRef
| Member | What it is |
|---|---|
gsap | The GSAP instance. |
context | The live gsap.Context. undefined on the server and before first render. |
ready | Signal<boolean>, flips to true once the context exists. |
contextSafe(fn) | Wraps event handlers so anything they create joins the context and its cleanup. |
revert() | Reverts everything; elements go back to their pre-animation state. |
kill() | Kills everything without reverting inline styles. |
provideGsap(options?)
One-time global setup, usually in app.config.ts. All of it is optional, and none of it runs on the server.
provideGsap({
plugins: [ScrollTrigger, SplitText, Flip],
config: { nullTargetWarn: false },
defaults: { ease: 'power3.out' },
});| Option | What it does |
|---|---|
plugins | Registers GSAP plugins once (ScrollTrigger, SplitText, Flip, …). Import them from the gsap package; only what you import gets bundled. |
config | Passed to gsap.config(). |
defaults | Passed to gsap.defaults(): default vars for every tween. |
effects | Registered with gsap.registerEffect(), usable as gsap.effects.name() in any callback. |
target(source) / targets(source)
Unwrap viewChild / viewChildren queries (or plain ElementRefs and elements) into the DOM nodes GSAP expects. Pass the query signal itself: read inside a callback it stays tracked, so new elements re-run the animation.
box = viewChild.required<ElementRef>('box');
dots = viewChildren<ElementRef>('dot');
ref = injectGsap(({ gsap }) => {
gsap.to(target(this.box), { x: 100 });
gsap.from(targets(this.dots), { scale: 0 });
});Directives
Preset directives, all built on the injectGsap engine: reveal, stagger, splitReveal, scrambleText, drawSvg, counter, parallax, drag, scrollTo, observe, hover, and sequence, which composes child entrances into one timeline ([at] accepts GSAP position syntax). Import the classes you use or GSAP_DIRECTIVES for all of them. Every input is a signal: change one and the animation replays. Under reduced motion they don't animate (counter shows the final value).
<h1 reveal>Fades up</h1>
<ul stagger="0.08" preset="scale-in"><li>…</li></ul>
<p splitReveal="chars" on="scroll">…</p>
<span [counter]="12500" [decimals]="0"></span>
<img parallax="0.3" src="…" />| Input | Default | What it does |
|---|---|---|
reveal / preset | fade-up | One of fade, fade-up, fade-down, fade-left, fade-right, scale-in. |
on | init | init plays after first render; scroll when the element enters the viewport (needs ScrollTrigger in provideGsap). |
delay | 0 | Seconds before the entrance starts. |
duration | 0.7 | Entrance length in seconds. |
distance | 28 | Travel in px for the directional presets. |
ease | power3.out | Any GSAP ease string. |
start | top 85% | ScrollTrigger start, only used with on="scroll". |
scroller | the window | Scrollable container for on="scroll" and parallax: a selector, an element, or an ElementRef. |
stagger / each | 0.08 | Stagger only: seconds between each child. |
items | direct children | Stagger only: a CSS selector, resolved inside the host, for the staggered items. |
splitReveal / kind | words | SplitReveal only: chars, words, or lines. Needs SplitText in provideGsap; the stagger defaults per kind and each overrides it. |
counter / from / decimals | 0 | Counter only: the target number, the starting number, and the fraction digits. Formatted with the user's locale. |
drawSvg / each | 0.15 | DrawSvg only: seconds between strokes when the host contains several. Needs DrawSVGPlugin in provideGsap. |
sequence / at | in order | The container's attribute value is the gap between steps; each child's at is a GSAP position parameter. |
parallax | 0.15 | Parallax only: fraction of the viewport height the element drifts while crossing it; negative moves against the scroll. Needs ScrollTrigger. |
The entrance directives and counter emit a completed output when they finish.
Plugin coverage
The whole GSAP catalog works here, because nothing is wrapped. Where this table says "vars" or "callback", use the plugin inside injectGsap exactly as the GSAP docs show.
| Plugin | How you use it |
|---|---|
| ScrollTrigger, SplitText, DrawSVG, ScrambleText, ScrollTo, Draggable, Inertia, Observer | Directives (reveal/staggeron="scroll", parallax, splitReveal, drawSvg, scrambleText, scrollTo, drag, observe) or raw in the callback. Examples throughout. |
| Flip, MorphSVG, MotionPath | Raw in the callback; see the Flip, SVG, and Observer & Inertia example pages. |
| Text, Physics2D, PhysicsProps | Property plugins: register them, then use text/physics2D/physicsProps vars in any tween. |
| EasePack (rough, slow, expoScale), CustomEase, CustomBounce, CustomWiggle | Register through provideGsap, then use them as ease strings (ease: 'rough(…)') or create curves in the callback (CustomEase.create()). |
| ScrollSmoother | Deliberately un-wrapped: it's a page-level singleton that owns the body scroll. Create it once in your app shell's injectGsap callback. |
| GSDevTools, MotionPathHelper | Dev tools: create them in the callback during development (GSDevTools.create({ animation: tl })); the context cleans them up. |
| Pixi, Easel | Canvas-library bridges; register and tween Pixi/Easel objects from the callback like any other target. |
Anything GSAP doesn't track (a gsap.ticker loop, an event listener): return a cleanup function from the callback and it runs on destroy.
Tree-shaking plugins
The library imports no GSAP plugin, ever, so your bundle contains exactly the plugins your app imports and nothing else. Register only what a given scope uses; provideGsap also works in lazy route providers, which puts a plugin's code in that route's chunk instead of the main bundle:
// main bundle: no plugins at all
{
path: 'gallery',
loadComponent: () => import('./gallery'),
// Flip ships in the gallery chunk only
providers: [provideGsap({ plugins: [Flip] })],
},Types
Re-exports so you rarely import from gsap directly: Gsap, GsapTween, GsapTimeline, GsapContext, GsapTweenVars, GsapTimelineVars, GsapConfig. Plus the library's own: GsapRef, GsapCallback, InjectGsapOptions, GsapOptions, RevealPreset, ElementLike, and a prefersReducedMotion() helper.