英文:
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()
]
})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论