这是我的index.html中的代码
<html ng-app="">
<head>
<link rel="stylesheet" href="css/app.css">
<link rel="stylesheet" href="css/bootstrap.css">
<script src="lib/angular/angular.js"></script>
<script src="js/phoneControllers.js"></script>
<title ng-bind-template="Google Phone Gallery:{{query}}">Google Phone Gallery</title>
</head>
<body ng-controller="PhoneListCtrl">
<div class="container-fluid">
<div class="row-fluid">
<div class="span2">
Search:
<input ng-model="query">
Sory by:
<select ng-model="orderProp">
<option value="name">Alphabetical</option>
<option value="age">Newest</option>
</select>
</div>
<div class="span10">
<h1>{{Hello}}</h1>
<p>Total number of phones:{{filtered.length}}</p>
<ul class="phones">
<li ng-repeat="phone in filtered=(phones | filter:query | orderBy:orderProp)" class="thumbnail">
<span>{{$index}}</span>
<a href="#/phones/{{phone.id}}" class="thumb"><img ng-src="{{phone.imageUrl}}" /></a>
<a href="#/phones/{{phone.id}}">{{phone.name}}</a>
<p>{{phone.snippet}}</p>
</li>
</ul>
</div>
</div>
</div>
<div id="currentFilter">Current filter: {{query}}</div>
<div id="currentOrderPrep">Current Order: {{orderProp}}</div>
<!--<div>{{phones|json}}</div>-->
</body>
</html>
当我使用Chrome Inspector打开它时,它经常会抛出这个:
return ensure(modules, name, function() {
if (!requires) {
throw $injectorMinErr('nomod', "Module '{0}' is not available! You either misspelled " +
"the module name or forgot to load it. If registering a module ensure that you " +
"specify the dependencies as the second argument.", name);
}
这是phoneControllers.js:
function PhoneListCtrl($scope, $http) {
$http.get('phones/phones.json').success(function (data) {
$scope.phones = data;
});
$scope.orderProp = "age";
};
但在关闭Chrome Web Inspector时,一切顺利进行。 你能告诉我发生了什么吗?提前致谢
我读了angular.js代码,看来这是Angular bug,无论何时,都会抛出这个错误。
var $injectorMinErr = minErr('$injector');
var ngMinErr = minErr('ng');
function ensure(obj, name, factory) {
return obj[name] || (obj[name] = factory());
}
var angular = ensure(window, 'angular', Object);
// We need to expose `angular.$$minErr` to modules such as `ngResource` that reference it during bootstrap
angular.$$minErr = angular.$$minErr || minErr;
return ensure(angular, 'module', function() {
/** @type {Object.<string, angular.Module>} */
var modules = {};
return function module(name, requires, configFn) {
var assertNotHasOwnProperty = function(name, context) {
if (name === 'hasOwnProperty') {
throw ngMinErr('badname', 'hasOwnProperty is not a valid {0} name', context);
}
};
assertNotHasOwnProperty(name, 'module');
if (requires && modules.hasOwnProperty(name)) {
modules[name] = null;
}
return ensure(modules, name, function() {
if (!requires) {
throw $injectorMinErr('nomod', "Module '{0}' is not available! You either misspelled " +
"the module name or forgot to load it. If registering a module ensure that you " +
"specify the dependencies as the second argument.", name);
}
永远不会定义变量需要。我是一个新鲜的,任何错误,请告诉我。
答案 0 :(得分:4)
答案 1 :(得分:2)
施洛米
答案 2 :(得分:1)
好吧,我没有看到任何类型的角度自举文件,所以看起来你还没有模块,所以错误是有道理的。制作一个app.js
文件,并将其放入其中
var app = angular.module('app',
[
// you'll use this space later, for stuff like ngRoute and ngResource,
]);
然后在html中加载文件并将<html ng-app="">
更改为<html ng-app="app">