Search code examples
angularangular-standalone-componentsangular16

Importing the BrowserModule into a standalone Angular16 project


Angular 16 is recently released and I have created a new standalone project without any module. then in a standalone component I need to import BrowserAnimationsModule from angular/platform-browser/animations. but when I import it, this error occures:

Poviders from the BrowserModule have already been loaded. If you need access to common directives such as NgIf and NgFor, import the CommonModule instead.

and when I remove it this one:

Unexpected synthetic listener @animation.start found. Please make sure that: Either BrowserAnimationsModule or NoopAnimationsModule are imported in your application.

so why first error occures? where is BrowserModule already loaded? and if it has already been imported how do I use it?


Solution

  • You have provideAnimations() for this !

    bootstrapApplication(AppComponent, {
        providers: [
          provideAnimations()
        ]
     })