Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk3 min

Reusable Animations in Angular: Legacy API and the Current CSS Approach

Angular’s legacy DSL reuses parameterized animations with animation() and useAnimation(). For new enter-and-leave effects, Angular recommends CSS animate.enter and animate.leave.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In Angular’s legacy animation DSL, define a reusable animation with animation(), export it from a TypeScript module, and invoke it in a component transition with useAnimation(). For new enter-and-leave effects, Angular now recommends CSS with animate.enter and animate.leave: the legacy animation package is deprecated, and Angular’s API reference says the two reusable-animation functions were deprecated in v20.2 with removal intended for v23—not yet a completed removal.

How reusable animations work in the legacy DSL

A reusable animation is a shared metadata definition, not a component trigger by itself. Define its steps once, export the reference, then call it from a component’s trigger and transition. Placeholders let each call supply its own timing or style values.

As an Amazon Associate I earn from qualifying purchases.

  1. Define and export the animation. In a TypeScript module, compose steps with helpers such as style() and animate(), wrap them in animation(), and export the result.
  2. Add parameters where callers need variation. Use placeholders such as {{ time }} in a timing value or {{ opacity }} in a style value. The official guide’s example also demonstrates height and background-color parameters; its particular values are illustrative, not required design choices. Angular’s reusable animations guide shows the full definition and call-site pattern.
  3. Invoke it from a component transition. Import the exported reference and pass it to useAnimation() inside a transition in the component’s animation metadata. Supply a params object with values for the placeholders used by the definition.
  4. Set defaults if they make sense. Defaults on the definition can cover common values; invocation parameters override them. If a required placeholder has neither a supplied value nor a default, Angular documents that invocation as an error. See the animation API reference and useAnimation API reference.

This structure is useful when an existing application uses Angular’s legacy animation metadata and several transitions need the same steps with different parameter values.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What to use for new enter-and-leave effects

Angular’s current direction for new work is CSS, using the compiler-supported animate.enter and animate.leave APIs. They apply CSS classes when an element enters or leaves the DOM, or can call a function to use an animation library. Consult the current animations guide for the supported enter-and-leave workflow.

These APIs are specifically documented for element entry and removal. The documentation does not establish that they replace every sequencing or coordination feature in the legacy DSL, so choose based on what the effect needs rather than assuming feature-for-feature equivalence.

Situation Approach indicated by Angular’s documentation Important boundary
New effect tied to an element entering or leaving CSS with animate.enter or animate.leave These APIs cover enter and leave behavior; the cited guidance does not claim parity with every legacy DSL feature.
Existing code shares parameterized legacy animation steps animation() and useAnimation() describe the legacy reuse pattern Both functions are documented as deprecated in v20.2, with removal intended in v23.
Nested legacy component animations need coordination Use the legacy child-animation mechanism where applicable animateChild() is for Angular-library animations with query(); it does not handle CSS keyframes or transitions.

The legacy package deprecation and recommended direction are stated in the legacy animations overview. The v20.2 deprecation and v23 removal intent are recorded in the animation API reference and useAnimation API reference. Removal is an intention in that documentation, not evidence that the API has already been removed.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why a child animation may not run

In the legacy animation system, an animation on a parent can take priority and block animations on its children. If a parent transition needs to coordinate child animations, Angular’s documented pattern is to query the child animation elements and run them with animateChild().

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

This is a legacy Angular animation-library mechanism, not a general way to launch CSS keyframes or transitions. The transition guide explains parent-child handling; the animateChild API reference describes its scope and its use with query().

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.