当使用angular 1.2而不是1.07时,下面这段代码就不再有效了,为什么?

'use strict';

var app = angular.module('myapp', []);

app.config(['$routeProvider', '$locationProvider',
    function($routeProvider, $locationProvider) {
        $locationProvider.html5Mode(true);
        $routeProvider.
        when('/', {
            templateUrl: 'part.html',
            controller: 'MyCtrl'
        }).
        otherwise({
            redirectTo: '/'
        });
    }
]);

问题出在注入器配置部分(app.config):

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.2.0rc1/$injector/modulerr?p0=muninn&p1=Error%…eapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.0rc1%2Fangular.min.js%3A31%3A252) 

如果我没记错的话,这个问题是从angular 1.1.6开始的。


当前回答

约翰爸爸在这个相当晦涩的评论中提供了我的问题:有时当你得到这个错误时,这意味着你丢失了一个文件。其他时候,它意味着模块是在使用之后定义的。一种简单的解决方法是将模块文件命名为*.module.js并首先加载这些文件。

其他回答

还有一件事要添加到列表中,因为这是谷歌搜索'Error: [$injector:modulerr] angular'得到的第一个结果:

如果你在你的'index'html'和你的主javascript应用程序定义中有一个不匹配的应用程序名称,这也会产生这个错误。

例如,如果你的HTML是这样的:

    </head>
    <body ng-app="myWebSite">

        <!-- My Web Site -->
        <p>About my web site...</p>

        etc ...

和你的JavaScript看起来像这样(即有一个错别字的应用程序名称- myWebCite而不是myWebSite):

/** Main AngularJS Web Application */ 
var app = angular.module('myWebCite', [ 'ngRoute' ]); 

/** Configure the Routes */ 
app.config(['$routeProvider', function ($routeProvider) { 
  etc ...

那么也会生成'Error:[$injector:modulerr] angular'错误。

我刚刚经历了同样的错误,在我的情况下,这是由angular中的第二个参数引起的。模块丢失-希望这可以帮助有同样问题的人。

angular.module('MyApp');

angular。模块(’MyApp’,[]);

除了下面的答案,如果你在控制台([$injector:nomod], MINERR_ASSET:22)中出现这个错误,但一切似乎都正常工作,请确保你的index.html中没有重复的include。

因为如果您有使用此模块的文件的重复包含,并且包含在具有实际模块声明的文件之前,也会引发此错误。

这是注入器错误。你可能使用了很多JavaScript文件,所以注入器可能会丢失。

这里有一些:

var app = angular.module('app', 
    ['ngSanitize', 'ui.router', 'pascalprecht.translate', 'ngResource', 
     'ngMaterial', 'angularMoment','md.data.table', 'angularFileUpload', 
     'ngMessages', 'ui.utils.masks', 'angular-sortable-view',          
     'mdPickers','ngDraggable','as.sortable', 'ngAnimate', 'ngTouch']
);

请检查你需要在app.js中插入的注入器

我有这个问题,检查我的代码行后,我看到了这个

 <textarea class="form-control" type="text" ng-model="WallDesc" placeholder="Enter Your Description"/>

我只是把它改成了

     <textarea class="form-control" type="text" ng-model="WallDesc" placeholder="Enter Your Description"></textarea>

这是有效的。 所以检查你的标签。