【发布时间】:2015-07-26 16:24:23
【问题描述】:
我正在尝试学习 Angular,但在尝试向我的应用程序添加路由时遇到了困难。
我不断收到此错误
'modulerr', "无法实例化模块
从其他 stackoverflow 问题中,我不是从正确加载 ngRoute 获得的,而是在头部加载了 angular-route.js,并且在我的模块构造中声明了 ngRoute,所以我有点困惑
我的索引文件如下
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-route.js"></script>
<script src="https://cdn.firebase.com/js/client/2.2.4/firebase.js"></script>
<script src="https://cdn.firebase.com/libs/angularfire/1.1.2/angularfire.min.js"></script>
<script src="js/app.js"></script>
<script src="js/animations.js"></script>
<script src="js/controllers.js"></script>
<script src="js/filters.js"></script>
<script src="js/services.js"></script>
</head>
<body ng-app="pgpChatApp">
<div class="view-container">
<div ng-view="" class="view-frame"></div>
</div>
</body>
</html>
我的应用文件
'use strict';
var pgpChatApp = angular.module('pgpChatApp', [
'ngRoute',
'firebase',
'pgpChatAnimations',
'pgpChatControllers',
'pgpChatFilters',
'pgpChatServices'
]);
pgpChatApp.config(["$routeProvider", function ($routeProvider) {
$routeProvider.when("/home", {
// the rest is the same for ui-router and ngRoute...
controller: "userAuth",
templateUrl: "partials/home.html"
}).when("/account", {
// the rest is the same for ui-router and ngRoute...
controller: "AccountCtrl",
templateUrl: "partials/msg_room.html",
resolve: {
// controller will not be loaded until $requireAuth resolves
// Auth refers to our $firebaseAuth wrapper in the example above
"currentAuth": ["Auth", function (Auth) {
// $requireAuth returns a promise so the resolve waits for it to complete
// If the promise is rejected, it will throw a $stateChangeError (see above)
return Auth.$requireAuth();
}]
}
});
}]);
我的控制器文件
var pgpChatAppControllers = angular.module('pgpChatAppControllers', []);
pgpChatAppControllers.controller("userAuth", ["$scope", "$routeParams", "Auth",
function ($scope, $routeParams, Auth) {
$scope.createUser = function () {
$scope.message = null;
$scope.error = null;
Auth.$createUser({
email: $scope.email,
password: $scope.password
}).then(function (userData) {
$scope.message = "User created with uid: " + userData.uid;
}).catch(function (error) {
$scope.error = error;
});
};
$scope.removeUser = function () {
$scope.message = null;
$scope.error = null;
Auth.$removeUser({
email: $scope.email,
password: $scope.password
}).then(function () {
$scope.message = "User removed";
}).catch(function (error) {
$scope.error = error;
});
};
}]);
有人知道解决方法是什么吗?
在此致谢
[编辑] 完整的异常消息
http://errors.angularjs.org/1.3.15/$injector/modulerr?p0=pgpChatAnimations&p1=错误:[$injector:nomod] http://errors.angularjs.org/1.3.15/$injector/nomod?p0=pgpChatAnimations 在错误(本机) 在https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:6:417 在https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:21:412 在 (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:21:53) 在 w.bootstrap (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:21:296) 在https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:35:116 在 r (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:7:302) 在 g (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:34:399) 在https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:35:63 在 r (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:7:302)"
【问题讨论】:
-
你的代码在哪里引用了“modulerr”? *注意双 r。
-
在 angularfire 之后加载 angular 会导致额外的错误,angularfire 是 angular 的 firebase 插件。 @AndrewF 我在上面包含了完整的异常消息
-
在第一个文件中你有
var pgpChatApp = angular.module('pgpChatApp', ...),然后在第二个文件中:var pgpChatAppControllers = angular.module('pgpChatAppControllers', [])——你可能不想要第二个模块,应该将控制器添加到pgpChatApp。 -
好的,那么您应该按原样加载 js 文件,但没有协议。喜欢
src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"。确保所有这些 -
@JamesKirkby 创建小提琴 ..
标签: javascript jquery angularjs html model-view-controller