简体   繁体   中英

Angular Js Uncaught Error: [$injector:modulerr] anonymous function

I'm new in using angular js and I just can't find what's going wrong.It gives these errors:

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.4.9/ $injector/modulerr?p0=rest&p1=Error%3A%20… ogleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.9%2Fangular.min.js%3A19%3A463)(anonymous function) @ angular.js:38(anonymous function) @ angular.js:4470n @ angular.js:341g @ angular.js:4431db @ angular.js:4356c @ angular.js:1677zc @ angular.js:1698ce @ angular.js:1592(anonymous function) @ angular.js:29652b @ angular.js:3069Of @ angular.js:3358Nf.d @ angular.js:3346

Here is my code in Plnkr

Your controller function definition for the first controller in the controller.js file is wrong. Check the services you are injecting into the controller, the ones in the square bracket do not match the function arguments.

There were a lot of mistakes:

1) while referring to js files in plunker , don't give /controllers.js instead give controllers.js

2) for loading js files, you have specified type="app.js" instead of src="app.js"

<script src="controllers.js"></script>
<script src="services.js"></script>
<script src="app.js"></script>

3) you forgot to load ng-resource.js

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular-resource.min.js"></script>

4) the config section with the route provider was not correct. the syntax was wrong.

This is correct:

rest.config(['$routeProvider', function ($routeProvider) {
        $routeProvider.when('/index', {templateUrl: 'index.html', controller: 'taskListCtrl'}).
        when('/account', {templateUrl: 'account.html', controller: 'accountListCtrl'});
        $routeProvider.otherwise({redirectTo: '/index'});
    }])

5) you need to load controllers.js and services.js before app.js

6) you can't have dependency on modules that do not exist, like rest.filters and rest.directives

var rest = angular.module('rest', ['ngRoute', 'rest.services','rest.controllers']);

Here is the updated plunker:

http://plnkr.co/edit/hTCnNaXgCAKUUPCXrIT3?p=preview

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM