Angular JS,'nomod',模块'{0}'不可用!你要么拼错了

时间:2014-03-10 09:06:15

标签: javascript angularjs

这是我的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);
    }

永远不会定义变量需要。我是一个新鲜的,任何错误,请告诉我。

3 个答案:

答案 0 :(得分:4)

我必须将您链接到AngularJS文档

Angularjs $injector::nomod

基本上说你的模块应该定义为:

angular.module('myApp',[]);

答案 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">