找到合成属性@enterAnimation。请包含“BrowserAnimationsModule”和“BrowserAnimationsModule”。或“NoopAnimationsModule”或在你的申请中。 Angular4 [英] Found the synthetic property @enterAnimation. Please include either "BrowserAnimationsModule" or "NoopAnimationsModule" in your application. Angular4

查看:130
本文介绍了找到合成属性@enterAnimation。请包含“BrowserAnimationsModule”和“BrowserAnimationsModule”。或“NoopAnimationsModule”或在你的申请中。 Angular4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当运行Karma来测试我的Angular4应用程序时,我收到此错误找到合成属性@enterAnimation。请在您的应用程序中包含BrowserAnimationsModule或NoopAnimationsModule。虽然我已经在 app.module.ts中导入了该模块

When running Karma to test my Angular4 application, I get this error Found the synthetic property @enterAnimation. Please include either "BrowserAnimationsModule" or "NoopAnimationsModule" in your application. though I already imported the module in app.module.ts

        // animation module
        import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 
    ...
@NgModule({
    imports: [...
        BrowserAnimationsModule,
        ...
      ],

和我的组件

 import { Component, OnInit } from '@angular/core';
    import {
      trigger,
      state,
      style,
      animate,
      transition
    } from '@angular/animations';

    @Component({
      selector: 'app-about',
      animations: [
        trigger(
          'enterAnimation', [
            transition(':enter', [
              style({ transform: 'translateX(100%)', opacity: 0 }),
              animate('500ms', style({ transform: 'translateX(0)', opacity: 1 }))
            ]),
            transition(':leave', [
              style({ transform: 'translateX(0)', opacity: 1 }),
              animate('500ms', style({ transform: 'translateX(100%)', opacity: 0 }))
            ])
          ]
        ),
        trigger(
          'enterAnimationVetically', [
            transition(':enter', [
              style({ transform: 'translateY(100%)', opacity: 0 }),
              animate('500ms', style({ transform: 'translateY(0)', opacity: 1 }))
            ]),
            transition(':leave', [
              style({ transform: 'translateY(0)', opacity: 1 }),
              animate('500ms', style({ transform: 'translateY(100%)', opacity: 0 }))
            ])]
        )
      ],
...

该应用程序与 ng服务然而,我在业力时遇到了这个错误。

The application runs perfectly with ng serve yet, I got this error with karma.

推荐答案

我找到了解决方案。我只需要导入 app.component.spec.ts 相同的导入

I found the solution. I just needed to import in app.component.spec.ts the same import

 // animation module
        import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 
    ...
@NgModule({
    imports: [...
        BrowserAnimationsModule,
        ...
      ],

这篇关于找到合成属性@enterAnimation。请包含“BrowserAnimationsModule”和“BrowserAnimationsModule”。或“NoopAnimationsModule”或在你的申请中。 Angular4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆