AngularJS 1.2 $注入器:模块

当使用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) 

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

西门猴子2020/03/13 20:05:15

Sometime I have seen this error when you are switching between the projects and running the projects on the same port one after the other. In that case goto chrome Developer Tools > Network and try to check the actual written js file for: if the file match with the workspce. To resolve this select Disable Cache under network.

村村番长前端2020/03/13 20:05:15

My problem was in the config.xml. Changing:

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

to

<access origin="*"/>

fixed it.

蛋蛋阿飞2020/03/13 20:05:15

John Papa provided my issue on this rather obscure comment: Sometimes when you get that error, it means you are missing a file. Other times it means the module was defined after it was used. One way to solve this easily is to name the module files *.module.js and load those first.

飞云JinJin2020/03/13 20:05:15

除了下面的答案,如果你在控制台有这个错误([$injector:nomod]MINERR_ASSET:22),但一切似乎做工精细,确保你没有重复的包含您的index.html。

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

Green小宇宙伽罗2020/03/13 20:05:15

我遇到了同样的问题,并尝试了所有可能的解决方案。但是最后我从文档中得知ngRoute模块已分离。看看这个链接

解决方案:angular.min.js脚本之后 添加CDN angular-route.js

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.js"></script>
Tom凯2020/03/13 20:05:15

一个菜鸟错误可能会忘记包括模块js

<script src="app/modules/myModule.js"></script>

完全在index.html中的文件

达蒙武藏2020/03/13 20:05:15

如果您在控制台中遇到此错误([$injector:nomod], MINERR_ASSET:22),请确保在加载之前不包括应用程序代码AngularJS

我这样做了,确定订单后,错误就消失了。