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

标签 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 的 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的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);
    }

永远不会定义变量requires。我是新手,有什么不对的地方,请告诉我。

最佳答案

我必须将您链接到 AngularJS 文档

Angularjs $injector::nomod

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

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

关于javascript - Angular JS, 'nomod',模块 '{0}' 不可用!你要么拼错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22295911/

相关文章:

javascript - 如何在reactjs中使单选按钮工作并输出值

angularjs - 增加 ui.grid 中列的宽度

angularjs - 使用 Moment.js 的 Angular 过滤日期(过去/ future )

javascript - YouTube 视频无法使用 ng-src 指令从 html5 播放

javascript - 如何在 HTML 表格上使用分页?

javascript - 如何使用 XPath 或 CSS 选择可见元素?

javascript - 为什么我无法直接将子节点附加到文档对象模型?

javascript - 在 keyup 上向 API 发出请求,但我无法访问范围内的内容

angularjs - Yeoman 生成器使用 gulp 和 angular 与 express 服务器

javascript - 从文本中删除文本和数字