无法在角度js中注入模块

时间:2016-05-21 11:19:59

标签: javascript angularjs

我正在尝试使用此处的HandsonTable module https://github.com/handsontable/ngHandsontable

我已经加载了脚本并注入了依赖项:

<script src="bower_components/angular/angular.min.js" type="text/javascript"></script>
<script src="bower_components/handsontable/dist/handsontable.full.js" type="text/javascript"></script>
<script src="bower_components/handsontable/dist/handsontable.js" type="text/javascript"></script>
<script src="bower_components/handsontable/dist/pikaday/pikaday.js" type="text/javascript"></script>

Angular模块:

var myApp = angular.module('myApp', ['ui.router', 'angular-jwt', 'ngStorage', 'angular-storage', 'angularCSS', 'ngHandsontable', 'ngMoment', 'pikaday']);

我收到错误消息:Uncaught Error: Cannot find module 'pikaday'

未捕捉错误:[$injector:modulerr] http://errors.angularjs.org/1.5.5/$injector/modulerr?p0=myApp&p1=Error%3A%2…84%2FAngularSpring%2Fbower_components%2Fangular%2Fangular.min.js%3A21%3A19)

更新

我已经像这样对我的脚本标签进行了排序:                              

现在我收到这样的错误:

未捕捉错误:[$injector:modulerr] http://errors.angularjs.org/1.5.5/$injector/modulerr?p0=myApp&p1=Error%3A%2…84%2FAngularSpring%2Fbower_components%2Fangular%2Fangular.min.js%3A21%3A19)

2 个答案:

答案 0 :(得分:0)

试试这个:

<script src="bower_components/handsontable/dist/pikaday/pikaday.js" type="text/javascript"></script>
<script src="bower_components/angular/angular.min.js" type="text/javascript"></script>
<script src="bower_components/handsontable/dist/handsontable.full.js" type="text/javascript"></script>
<script src="bower_components/handsontable/dist/handsontable.js" type="text/javascript"></script>

var myApp = angular.module(&#39; myApp&#39;,[&#39; ui.router&#39;,&#39; angular-jwt&#39;,&#39; ngStorage&#39; ,&#39; angular-storage&#39; angularCSS&#39;&#39; ngHandsontable&#39;,&#39; ngMoment&#39;,&#39; pikaday&#39;]);

答案 1 :(得分:0)

似乎pikaday没有被定义为角度模块,它被定义为全局Pikaday对象,如果你不使用commonJs或AMD加载器:

(function (root, factory)
{
    'use strict';

    var moment;
    if (typeof exports === 'object') {
        // CommonJS module
        // Load moment.js as an optional dependency
        try { moment = require('moment'); } catch (e) {}
        module.exports = factory(moment);
    } else if (typeof define === 'function' && define.amd) {
        // AMD. Register as an anonymous module.
        define(function (req)
        {
            // Load moment.js as an optional dependency
            var id = 'moment';
            try { moment = req(id); } catch (e) {}
            return factory(moment);
        });
    } else {
        root.Pikaday = factory(root.moment);
    }
}(this, factory))

而且我认为你不需要使用的是角度模块。尝试简单地从角度模块依赖项中删除它。 handsontable在内部引用它也是全局的,而不是角度模块。

<强>更新

尝试像这样加载:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<script src="bower_components/handsontable/dist/handsontable.full.js"></script>
<script src="bower_components/ngHandsontable/dist/ngHandsontable.js"></script>

var myModule = angular.module('myModule', ['ngHandsontable'])

对我来说没有错误