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


当前回答

如果你浏览angularjs的官方教程https://docs.angularjs.org/tutorial/step_07

注意:从AngularJS的1.2版本开始,ngRoute就独立了 模块,必须通过加载额外的angular-route.js来加载 文件,我们通过上面的Bower下载。

另外请注意ngRoute api https://docs.angularjs.org/api/ngRoute

Installation First include angular-route.js in your HTML: You can download this file from the following places: Google CDN e.g. //ajax.googleapis.com/ajax/libs/angularjs/X.Y.Z/angular-route.js Bower e.g. bower install angular-route@X.Y.Z code.angularjs.org e.g. "//code.angularjs.org/X.Y.Z/angular-route.js" where X.Y.Z is the AngularJS version you are running. Then load the module in your application by adding it as a dependent module: angular.module('app', ['ngRoute']); With that you're ready to get started!

其他回答

该问题是由于缺少包含ngRoute模块造成的。从1.1.6版本开始,它是一个单独的部分:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular-route.min.js"></script>

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

如果你浏览angularjs的官方教程https://docs.angularjs.org/tutorial/step_07

注意:从AngularJS的1.2版本开始,ngRoute就独立了 模块,必须通过加载额外的angular-route.js来加载 文件,我们通过上面的Bower下载。

另外请注意ngRoute api https://docs.angularjs.org/api/ngRoute

Installation First include angular-route.js in your HTML: You can download this file from the following places: Google CDN e.g. //ajax.googleapis.com/ajax/libs/angularjs/X.Y.Z/angular-route.js Bower e.g. bower install angular-route@X.Y.Z code.angularjs.org e.g. "//code.angularjs.org/X.Y.Z/angular-route.js" where X.Y.Z is the AngularJS version you are running. Then load the module in your application by adding it as a dependent module: angular.module('app', ['ngRoute']); With that you're ready to get started!

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

angular.module('MyApp');

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

这个错误的另一个触发点是在你的路由定义中把"."放在" else "或任何其他路由之前:

  app.config(['$routeProvider',
     function($routeProvider) {
        $routeProvider.
           when('/view1', {
              templateUrl: 'partials/view1.html',
              controller: 'Ctrl1'
           }).
           otherwise({
              redirectTo: '/viewCounts'
           });
     }]);

再一次被句号羞辱。爱死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>

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