如何在使用Yeoman的Angular项目中引入ngAnimate依赖

6
我正在使用yeoman、gruntjs和bower的组合创建一个angular应用程序。我使用yo angular myapp安装了我的angular应用程序,然后使用bower添加了一些依赖项,最后运行grunt server并开始工作。
只有当我尝试添加ng-animate依赖项时,我遇到了问题。这个依赖项被下载了,但它的脚本标记没有添加到index.html中,并且所需的引用没有添加到karma.conf.js文件中。
我已经尝试手动添加这两个引用: 在index.html中:
<script src="bower_components/angular-animate/angular-animate.js"></script>

karma/conf.js中。
files: [
  ...
  'app/bower_components/angular-animate/angular-animate.js',
  ...
],

但这种方法仅适用于已经运行的grunt server。如果我停止服务器并重新运行它,我手动添加的这两个引用将会消失。我该如何解决这个问题?

谢谢。

2个回答

14

你需要这样做:


1. 使用 bower 进行安装:

bower install angular-animate

2. 在你的 index.html 文件中添加一个 < script /> 标签:

< script src="/bower_components/angular-animate/angular-animate.js"></script >

3. 将ngAnimate添加为您的应用程序的依赖项:

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

请查看ng-newsletter 有关ngAnimate的文章,以获取更多关于这些步骤的信息


4
你可以尝试以下两种解决方案之一:
  1. 将其添加到你的bower.json文件中作为依赖项,然后运行 bower update

或者

  1. 在你的项目目录中打开终端并运行:bower install angular-animate

任何一种方法都会将其保留到你的bower.json文件中,并在再次运行grunt server时不会被删除。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接