【问题标题】:angularJS failed to load moduleangularJS 无法加载模块
【发布时间】:2015-02-09 16:55:25
【问题描述】:

有谁知道我为什么会遇到以下问题:

未捕获的错误:[$injector:modulerr] http://errors.angularjs.org/1.3.6/$injector/modulerr?p0=helloKinveyApp&p1=E...ogleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.6%2Fangular.min.js%3A17%3A350) angular.min.js:6 (匿名函数)angular.min.js:36 (匿名函数)angular.min.js:7 rangular.min.js:35 gangular.min.js:38 Obangular.min.js:17 dangular.min.js:18 scangular.min.js:16 Hdangular.min.js:249(匿名函数)angular.min.js:163 aangular.min.js:32 c

var app = angular.module("helloKinveyApp", ["ngRoute", "kinvey"]);

app.run(["$kinvey", function($kinvey) {
    var promise = $kinvey.init({
       appKey: clientParams.appKey
        , appSecret: clientParams.appSecret
    });

    promise.then(function() {
        console.log("Kinvey init with success");
    }, function(errorCallback) {
        console.log("Kinvey init with error: " + JSON.stringify(errorCallback));
    });
}]);

<!DOCTYPE html>
<html data-ng-app="helloKinveyApp">
    <head>
        <title>Hello Kinvey Lesson 1</title>
    </head>
    <body>
        <div data-ng-view="" />
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular.min.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular-route.min.js"></script>
        <script src="https://da189i1jfloii.cloudfront.net/js/kinvey-angular-1.1.4.min.js"></script>
    </body>
</html>

【问题讨论】:

  • 使用非缩小版的 Angular,您将获得有关该问题的更多详细信息
  • 以下行位于应用程序的哪个部分var app = angular.module("helloKinveyApp", ["ngRoute", "kinvey"]);
  • 那么 jQuery 标签在这里做什么?
  • 可能是你没有包含定义模块的js文件?
  • 将 kinvey.js 加载置于 angular.js 文件加载之上

标签: javascript jquery angularjs html kinvey


【解决方案1】:

如果您的代码的结构类似于以下,它应该可以工作(即您应该收到模块加载错误):

...
<body>
    ...
    <div data-ng-view="" />
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular.min.js">
    </script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular-route.min.js">
    </script>
    <script src="https://da189i1jfloii.cloudfront.net/js/kinvey-angular-1.1.4.min.js">
    </script>
    ...
    <script>
        var app = angular.module("helloKinveyApp", ["ngRoute", "kinvey"]);

        app.run(["$kinvey", function($kinvey) {
            var promise = $kinvey.init({
               appKey: clientParams.appKey,
               appSecret: clientParams.appSecret
            });

            promise.then(function() {
                console.log("Kinvey init with success");
            }, function(errorCallback) {
                console.log("Kinvey init with error: " + JSON.stringify(errorCallback));
            });
        }]);
    </script>
</body>

【讨论】:

  • 我忘记在 index.html 中引用 app.js
  • 就是这样。它应该在 angular 和 kinvey 之下,因为它依赖于它们。放在最后,你的问题应该得到解决。
  • 如果它有助于解决您的问题,请不要忘记选择此作为答案。
猜你喜欢
  • 2012-10-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-08
  • 2015-07-15
  • 2021-01-11
  • 1970-01-01
  • 2016-10-09
相关资源
最近更新 更多