将BrowserModule导入独立的Angular 16项目中。

huangapple go评论63阅读模式
英文:

Importing the BrowserModule into a standalone Angular16 project

问题

Angular 16最近发布,我已经创建了一个新的独立项目,没有任何模块。然后在一个独立的组件中,我需要从angular/platform-browser/animations导入BrowserAnimationsModule。但当我导入它时,出现以下错误:

> 来自BrowserModule的提供者已经被加载。如果你需要访问常见的指令,如NgIf和NgFor,请改为导入CommonModule

当我移除它时,出现以下错误:

> 发现意外的合成监听器@animation.start。请确保:要么在应用程序中导入BrowserAnimationsModule,要么导入NoopAnimationsModule

为什么首先会出现第一个错误?BrowserModule已经在哪里加载了?如果它已经被导入,我该如何使用它?

英文:

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?

答案1

得分: 2

你可以使用 provideAnimations() 来完成这个任务!

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

You have provideAnimations() for this !

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

huangapple
  • 本文由 发表于 2023年5月10日 19:17:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/76217757.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定