当使用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开始的。


当前回答

我的问题在config.xml中。改变:

<access origin="*" launch-external="yes"/>

to

<access origin="*"/>

固定它。

其他回答

在最后加上这个“()”,我的错误就消失了

(function(){
    var home = angular.module('home',[]);

    home.controller('QuestionsController',function(){
        console.log("controller initialized");
        this.addPoll = function(){
            console.log("inside function");
        };
    });
})();

对于那些使用压缩、捆绑和缩小文件的框架的人,请确保显式地定义每个依赖项,因为这些框架倾向于重命名变量。我在使用ASP时遇到了这种情况。NET BundleConfig.cs将我的应用程序脚本捆绑在一起。

之前

app.config(function($routeProvider) {
    $routeProvider.
      when('/', {
          templateUrl: 'list.html',
          controller: 'ListController'
      }).
      when('/items/:itemId', {
          templateUrl: 'details.html',
          controller: 'DetailsController'
      }).
      otherwise({
          redirectTo: '/'
      });
});

app.config(["$routeProvider", function($routeProvider) {
    $routeProvider.
      when('/', {
          templateUrl: 'list.html',
          controller: 'ListController'
      }).
      when('/items/:itemId', {
          templateUrl: 'details.html',
          controller: 'DetailsController'
      }).
      otherwise({
          redirectTo: '/'
      });
}]);

点击这里阅读更多关于Angular依赖注释的内容。

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

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

angular.module('MyApp');

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

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

 <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>

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