BrowserAnimationsModule in an Angular application?Importing BrowserAnimationsModule enables Angular's animation features to work in the browser environment. Without it, animations won't run.
BrowserAnimationsModule in an Angular standalone component?The correct import path is @angular/platform-browser/animations. For standalone components, you add it to the imports array inside the @Component decorator.
BrowserAnimationsModule in your app module?Without importing BrowserAnimationsModule, Angular cannot run animations and will throw an error at runtime indicating animation support is missing.
BrowserAnimationsModule?import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { AppComponent } from './app.component'; @NgModule({ declarations: [AppComponent], imports: [BrowserModule], bootstrap: [AppComponent] }) export class AppModule {}
Importing a module in the file is not enough; it must be added to the imports array of the @NgModule decorator to activate it.
BrowserAnimationsModule is correctly imported?import { Component } from '@angular/core'; import { trigger, state, style, transition, animate } from '@angular/animations'; @Component({ selector: 'app-fade', template: `<div [@fadeInOut]="isVisible ? 'visible' : 'hidden'">Fade Me</div> <button (click)="toggle()">Toggle</button>`, animations: [ trigger('fadeInOut', [ state('visible', style({ opacity: 1 })), state('hidden', style({ opacity: 0 })), transition('visible <=> hidden', [animate('500ms ease-in-out')]) ]) ] }) export class FadeComponent { isVisible = true; toggle() { this.isVisible = !this.isVisible; } }
With BrowserAnimationsModule imported, Angular runs the defined animation trigger. The div fades in and out smoothly over 500ms when toggled.
