javascript - ng-animate 在通过 webpack 加载时拒绝工作

标签 javascript angularjs animation ng-animate

我的工作流程目前正在使用 webpack、eslint 和 angular。在我的 app.js 中,我需要 ng-animate 如下:

require("angular-animate/angular-animate.min");

然后按如下方式将其添加到我的应用中:

var mainApp = angular.module("client", [
  //add the components here (personal and 3rd party).
  "ngAnimate",
)];

问题是 ng-animate 似乎没有加载,因为当我尝试在 css 中为 ng-enter 等设置动画甚至购买 javascript 路由时,它似乎不起作用。

ng-animate 和angular 的版本都是一样的,都是v1.6.3。我在这里可能做错了什么吗?我需要在 eslint 或 webpack 中做些什么可能会阻止 ng-animate 工作吗?

最佳答案

我遇到了这个问题,在找出我的问题之前花了太长时间来寻找答案。这可能有帮助,也可能没有帮助,但如果有人发现此问题,请检查以下内容。

我有一个类似的 webpack 设置,我的 app.js 文件大致如下所示:

import angular from 'angular';
import ngAnimate from 'angular-animate';

angular
  .module('app', [
    ngAnimate
  ]);

没有错误,所有代码似乎都已正确导入,但是当我的 ng-if 指令添加或删除我的标记时,我的 ng-enter/exit 类仍然没有被应用。

<p ng-if="$ctrl.test" class="the-test">THE TEST</p>

如果您通读 Angular 动画文档,您会发现:

For CSS transitions, the transition code must be defined within the starting CSS class (in this case .ng-enter). The destination class is what the transition will animate towards.

我意识到我没有在我试图设置动画的类上定义过渡属性...所以我将我的 CSS 更改为以下内容:

  .the-test {
    color: grey;
    transition: color 1s ease;
  }
  .the-test.ng-enter {
    color: red;
  }
  .the-test.ng-enter.ng-enter-active {
    color: blue;
  }

在那之后,一切开始正常工作。希望我浪费时间寻找一个并不真正存在的问题可以帮助其他人。

关于javascript - ng-animate 在通过 webpack 加载时拒绝工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43055627/

相关文章:

javascript - VideoJS 播放器无法在 iPad 上使用 AngularJS 播放

javascript - 创建一个脉动的圆圈

javascript - CSS 或 jQuery : How to add a fade effect to an element got with getElementById?

javascript - 摆脱 "regeneratorRuntime is not defined"而不导入 polyfill

javascript - CoffeeScript - 功能正在运行,但它是 "is not a function"

python - 在django项目中嵌入音乐播放器

C# Forms Authentication .ASPXAUTH Cookie for SSO

java - Spring mvc : how to pass parameters in mvc without method arguments at the controller

javascript - Google 表格自定义脚本

css - 有什么方法可以淡化 CSS ":active"样式,或者使用动画吗?