What's the difference between BrowserAnimationsModule and NoopAnimationsModule?

拜拜、爱过 提交于 2019-11-27 02:29:06

问题


With the new Angular-Material release, you need to add a module for Angular-Animations. You can choose between two BrowserAnimationsModule and NoopAnimationsModule. The official guide states:

Some Material components depend on the Angular animations module in order to be able to do more advanced transitions. If you want these animations to work in your app, you have to install the @angular/animations module and include the BrowserAnimationsModule in your app.

npm install --save @angular/animations
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';

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

If you don't want to add another dependency to your project, you can use the NoopAnimationsModule.

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

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

I don't quite get what is the difference here. Seems to be exactly the same :) What's the difference between the two modules?


回答1:


As the name noop ("no operation") says, that module doesn't do anything. It is a utility module that mocks the real animation module but doesn't actually animate.

This can be handy on platforms where animation would be too slow, or for unit testing, if animation isn't involved in what you actually want to test.




回答2:


BROWSER_ANIMATIONS_PROVIDERS is used for real application

Separate providers from the actual module so that we can do a local modification in Google3 to include them in the BrowserModule.

BROWSER_NOOP_ANIMATIONS_PROVIDERS is used for testing

Separate providers from the actual module so that we can do a local modification in Google3 to include them in the BrowserTestingModule.



来源:https://stackoverflow.com/questions/43362898/whats-the-difference-between-browseranimationsmodule-and-noopanimationsmodule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!