我已经对我得到的错误做了一些研究,但没有任何效果。错误:
Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.2.15/$injector/modulerr?p0=MemberModule&p1=Re…%20%20at%20http%3A%2F%2Flocalhost%3A3000%2Fjavascripts%2FMemberModule.js%3...<omitted>...5)
这是我的代码:
index.jade:
doctype html
html(ng-app="MemberModule")
head
title= title
link(rel='stylesheet', href='/javascripts/vendor/bootstrap-css/css/bootstrap.css')
link(rel='stylesheet', href='/stylesheets/style.css')
script(src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js")
script(src='https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular-route.min.js')
script(type='text/javascript', src='/javascripts/vendor/angular-bootstrap/ui-bootstrap-tpls.js')
script(src='https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js')
script(type='text/javascript', src='/javascripts/MemberModule.js')
#heady
block head
body
block content
如您所见 - 我想我正在以正确的顺序加载所有脚本。
MemberModule.js:
var MemberModule = angular.module('MemberModule', ['ui.bootstrap', 'ngRoute']);
MemberModule.config(function ($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider
.when('/member/:id.json', {
templateUrl: '/templates/home.jade',
controller: MemberListCtrl
});
});
MemberModule.controller('MemberListCtrl', ['$scope', '$routeParams',
function ($scope, $routeParams) {
$scope.id = $routeParams.id;
}
]);
我在MemberModule.js中猜它。提前谢谢。
更新
这就是firefox控制台所说的 - 更多信息,看起来没有定义:
[12:34:55.413] Error: [$injector:modulerr] http://errors.angularjs.org/1.2.15/$injector/modulerr?p0=MemberModule&p1=MemberListCtrl%20is%20not%20defined%0A%40http%3A%2F%2Flocalhost%3A3000%2Fjavascripts%2FMemberModule.js%3A9%0Ad%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.15%2Fangular.min.js%3A33%0Ae%2F%3C%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.15%2Fangular.min.js%3A32%0Ar%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.15%2Fangular.min.js%3A7%0Ae%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.15%2Fangular.min.js%3A32%0AZb%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.15%2Fangular.min.js%3A35%0AYb%2Fc%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.15%2Fangular.min.js%3A17%0AYb%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.15%2Fangular.min.js%3A18%0AUc%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.15%2Fangular.min.js%3A17%0A%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.15%2Fangular.min.js%3A206%0Aa%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.15%2Fangular.min.js%3A138%0Aie%2Fc%2F%3C%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.15%2Fangular.min.js%3A30%0Ar%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.15%2Fangular.min.js%3A7%0Aie%2Fc%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.15%2Fangular.min.js%3A30%0A @ https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js:6
更新
我没有使用谷歌CDN,而是下载了脚本并将它们放在站点目录中 - 没有更多的依赖性错误 - 但我确实有一个我不确定的错误(如果有人可以提供帮助):
[12:42:14.899] ReferenceError: MemberListCtrl is not defined @ http://localhost:3000/javascripts/MemberModule.js:9
我更新了我的MemberModule.js以反映它现在的样子。
答案 0 :(得分:0)
您收到未定义错误的原因是因为它未在尝试使用它的函数范围内定义。仅仅因为您使用Angular注册了具有该名称的对象并不意味着配置功能具有它。您需要注入该控制器或在模板中指定控制器(我个人喜好)。