How to disable animations in angular material

24.7k Views Asked by At

I have used angular material version: 5.2.1

And wanted to know how to disable their animations, especially the matDialog.

I have tried @.disabled but no luck.

2

There are 2 best solutions below

6
On BEST ANSWER

You can use NoopAnimationsModule by angular material

import {NoopAnimationsModule} from '@angular/platform-browser/animations';

@NgModule({
  ...
  imports: [NoopAnimationsModule],
  ...
})
export class PizzaPartyAppModule { }

Or if you want to remove transition on some specific components you can do it via CSS like this

.mat-dialog{ transition: none; }
0
On

The approved answer does not work and is not consistent with Angular docs, at least since Angular 6. To disable animations in Angular 6 to 13, from the official doc, use:

// In app.component.ts

import { Component, HostBinding } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent {
  @HostBinding('@.disabled')
  public animationsDisabled = true;  // Set to true to disable animations
}

This is useful for end-to-end (E2E) testing.