問題
當我將 aBrowserAnimationsModule或 a添加NoopAnimationsModule到獨立 AppComponent 的匯入陣列時,它會破壞應用程式。
@Component({
standalone: true,
imports: [
CommonModule,
NoopAnimationsModule,
/* ... */
],
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
這些是我添加其中任何一個時遇到的錯誤:
ERROR Error: Uncaught (in promise): Error: Providers from the `BrowserModule` have already been loaded.
If you need access to common directives such as NgIf and NgFor, import the `CommonModule` instead.
Error: Providers from the `BrowserModule` have already been loaded.
If you need access to common directives such as NgIf and NgFor, import the `CommonModule` instead.
當我不添加它時,我收到此錯誤:
ERROR Error: Unexpected synthetic property @transitionMessages found. Please make sure that:
- Either `BrowserAnimationsModule` or `NoopAnimationsModule` are imported in your application.
- There is corresponding configuration for the animation named `@transitionMessages` defined in
the `animations` field of the `@Component` decorator (see
https://angular.io/api/core/Component#animations).
到目前為止我的發現...
顯然BrowserAnimationsModule和NoopAnimationsModulecontains BrowserModule,我猜獨立組件也是如此。如何Browsermodule從影片模塊或獨立組件中排除?還是有其他一些影片模塊或解決方案可以幫助我解決這個問題?
如果您想親眼看看并嘗試一下,這里有一個Stackblitz 。
uj5u.com熱心網友回復:
該importProvidersFrom函式提供了回到 NgModule 世界的橋梁。它不應該在組件提供中使用,因為它只能在應用程式注入器中使用
添加importProvidersFrom函式以在 main.ts 中提供 BrowserAnimationModule。
main.ts
bootstrapApplication(AppComponent,{
providers:[importProvidersFrom(BrowserAnimationsModule)]
});
分叉示例
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/485603.html
