AngularJs - Error: [$injector:modulerr] Failed to instantiate module

1,690 views
Skip to first unread message

Renard

unread,
Apr 22, 2015, 12:43:58 PM4/22/15
to ang...@googlegroups.com
    I try running the index.html.It is just showing blank html page. And when i go to the debugger it says the above two errors
   
   
    Error: [$injector:nomod] Module 'pmapp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
   
    Error: [$injector:modulerr] Failed to instantiate module pmapp due to:
    VillecltController is not defined
   
    # here is my code #
   
     index.html
   
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="ISO-8859-1">
    <title>Insert title here</title>
    </head>
   
    <body ng-app="pmapp" ng-controller="VillecltController">
   
   
        <div ng-view></div>
   
        <script type="text/javascript"
            src="repository/angular-1.3.15/angular.js"></script>
        <script type="text/javascript"
            src="repository/angular-1.3.15/angular-route.js"></script>
        <script type="text/javascript"
            src="repository/angular-1.3.15/angular-resource.js"></script>
   
   
        <script src="scripts/js/controller.js"></script>
        <script src="scripts/js/service.js"></script>
        <script src="scripts/js/villeclt.js"></script>
   
   
    </body>
   
    </html>
   
    # controller.js #
    'use strict';
   
    angular.module('pmapp').controller('VillecltController', function($scope, villeclts) {
            $scope.Allvilleclts = villeclts.query();
            
   
        });
    # service.js #
    'use strict';
   
    angular.module('pmapp', ['ngResource'])
    .factory('villeclts', function($resource) {
       
        return $resource(
                'http://localhost:8080/projetForum/gestion/villeclients',
                {}, {
                    query : {
                        method : 'GET'
                        ,isArray : true
                    }
   
                });
    });
   
    # villeclt.js #
   
    'use strict';
   
    angular.module('pmapp', ['ngRoute']).config(function($routeProvider) {
        $routeProvider.when('/', {
            controller : VillecltController,
            templateUrl : 'scripts/js/partial.html'
           
        });
       
   
    });


SURESH tanneru

unread,
Apr 23, 2015, 1:59:16 AM4/23/15
to ang...@googlegroups.com
    you cannot create module twice with same name, instead u can get the module by the name for example  https://github.com/johnpapa/angular-styleguide#modules
      
          

Sander Elias

unread,
Apr 23, 2015, 3:36:35 AM4/23/15
to ang...@googlegroups.com
Hi Renard,

You are doing this: `angular.module('pmapp')` before you define your module like this `angular.module('pmapp', ['ngRoute'])`
This is not possible, an module must be created, before you can reuse it. This is one of the few things in angular where loading order matters.

Regards
Sander

Kamal Hafyane

unread,
Apr 23, 2015, 4:13:39 AM4/23/15
to ang...@googlegroups.com
Finally, I have no error  but my problem i can't access
 angular.module('pmapp', ['ngRoute'])
.config(function($routeProvider) {
    console.log("Provider-3");

    $routeProvider.when('/', {
        controller : VillecltController,
        templateUrl : 'scripts/js/partial.html'
       
    });

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/kgjhTDrD6og/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Sander Elias

unread,
Apr 23, 2015, 8:51:46 AM4/23/15
to ang...@googlegroups.com
Hi Renard,

I reread your code, you also declare your pmapp twice. this will not work either. Every module must be created only once, the second time will overwrite the old module. Probably the root cause of your problem.

regards
Sander
Reply all
Reply to author
Forward
0 new messages