Skip to content
Related Articles

Related Articles

Angular10 Trigger Animation

View Discussion
Improve Article
Save Article
  • Last Updated : 02 Jun, 2021
View Discussion
Improve Article
Save Article

In this article, we are going to see what is trigger in Angular 10 and how to use it.

The trigger in Angular10 is used to create an animation trigger containing state and transition of the animation.


animate(name | definations)

NgModule: Module used by trigger is:

  • animations



  • Create an angular app that to be used.
  • In app.module.ts, import BrowserAnimationsModule.
  • In app.component.html, make a div which will contain the animation element.
  • In app.component.ts, import the trigger, state, style, transition, animate to be used.
  • Make the trigger containing state and transition for the animation.
  • Serve the angular app using ng serve to see the output.


  • Name: Sets an identifying string.
  • definations: Sets an animation defination object.

Return Value:

  • AnimationTriggerMetadata: An object that encapsulates the trigger data.



import { LOCALE_ID, NgModule } 
from '@angular/core';
import { BrowserModule }
from '@angular/platform-browser';
import {BrowserAnimationsModule} 
from '@angular/platform-browser/animations';
import { AppRoutingModule }
from './app-routing.module';
import { AppComponent }
from './app.component';
  declarations: [
  imports: [
  providers: [
      { provide: LOCALE_ID, useValue: 'en-GB' },
  bootstrap: [AppComponent]
export class AppModule { }


import { 
  // Trigger is imported here
  animate } from '@angular/animations';
import { Component } from '@angular/core';
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ],
  animations: [
    // Trigger is used here
      state('green', style({
        'background-color': 'green',
        transform: 'translateX(0)'
      state('blu', style({
        'background-color': '#49eb34',
        transform: 'translateX(0)'
      transition('green => blu',animate(1200)),
      transition('blu => green',animate(1000))
export class AppComponent  {
  state = 'green';
    this.state == 'green' ?
    this.state = 'blu' : this.state = 'green';


<button (click)='anim()'>Animate</button>
  style="width: 150px; height: 100px; border-radius: 5px;"



My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!