【问题标题】:Angular JS, 'nomod',Module '{0}' is not available! You either misspelledAngular JS,“nomod”,模块“{0}”不可用!你要么拼错
【发布时间】:2015-04-19 20:30:02
【问题描述】:

这是我的 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 使用 Web 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 的错误,无论何时,都会抛出此错误。

 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);
    }

永远不要定义变量要求。我是新手,有什么错误,请告诉我。

【问题讨论】:

  • 你能做一个笨拙的人或摆弄你的代码,这样我们就可以看到你是如何定义你的应用程序的?尽管您可以将这行 ng-repeat="phone in filtered=(phones | filter:query | orderBy:orderProp)" 替换为: ng-repeat="phone in devices | filter:query | orderBy:orderProp"
  • @maurycy 我更新了我的帖子

标签: javascript angularjs


【解决方案1】:

我必须将您链接到 AngularJS 文档

Angularjs $injector::nomod

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

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

【讨论】:

    【解决方案2】:

    今天也发生在我身上 - 寻找没有人说出我的原因的答案。只是拼错了单词 function(可以是其他任何东西),导致整个模块无法加载。

    史洛米

    【讨论】:

      【解决方案3】:

      嗯,我没有看到任何类型的角度引导文件,所以看起来你还没有模块,所以这个错误是有道理的。创建一个app.js 文件,并将其放入其中

      var app = angular.module('app',
      [
          // you'll use this space later, for stuff like ngRoute and ngResource,
      ]);
      

      然后在您的html中加载文件并将&lt;html ng-app=""&gt;更改为&lt;html ng-app="app"&gt;

      【讨论】:

      • 我根据您的推荐添加了,仍然没有意义。这似乎是 AngularJS 中的常见错误
      猜你喜欢
      • 1970-01-01
      • 2014-08-24
      • 2017-09-26
      • 2016-07-21
      • 2017-06-29
      • 2014-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多