【问题标题】:Adding angular animate to pre-existing stack将角度动画添加到预先存在的堆栈
【发布时间】:2015-03-04 19:59:11
【问题描述】:

我已经克隆了这个 repo:https://github.com/Hyra/Frickle 它非常棒!但我正在尝试添加更多的角度模块,但我没有成功。

在主目录中我运行 npm install angular-animate。这会将 angular-animate 文件夹文件添加到项目中的 node_modules 文件夹中,与其他 angular 模块和 angular 库本身并排。

在 package.json 文件中,我通过添加以下内容将依赖项添加到 angular-animate 中

 "dependencies": {
    "angular": "~1.3.0",
    "angular-ui-router": "~0.2.11",
    "angular-animate": "~1.3.5",
...

在 main.js 中

'use strict';

require('angular');

var uiRoute = require('angular-ui-router');
var ngAnimate = require('angular-animate');
var app = angular.module('MyApp', [uiRoute, ngAnimate]);

Angular-ui-router 在原始设置中工作正常。该堆栈使用 gulp 和 browserify 来连接和缩小 javascript 文件,但由于我对 angular 有点陌生,我不确定为什么在向该堆栈添加简单依赖项时遇到问题。希望这很简单,有人可以告诉我我做错了什么。

我在控制台得到的错误如下:

Uncaught Error: [$injector:modulerr] Failed to instantiate module MyApp due to:
Error: [$injector:modulerr] Failed to instantiate module {} due to:
Error: [ng:areq] Argument 'module' is not a function, got Object

【问题讨论】:

    标签: angularjs node.js dependencies gulp dependency-management


    【解决方案1】:

    这看起来很奇怪:var app = angular.module('MyApp', [uiRoute, ngAnimate]);

    根据:https://code.angularjs.org/1.3.10/docs/api/ng/function/angular.module

    requires 数组应该是一个字符串数组。所以它真的应该是:

    var app = angular.module('MyApp', [uiRoute.name, ngAnimate.name]);
    

    【讨论】:

      猜你喜欢
      • 2021-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-17
      • 2017-02-28
      • 2014-08-01
      • 2016-11-04
      • 1970-01-01
      相关资源
      最近更新 更多