Mick
Mick

Reputation: 324

Angular.JS: Failed to instantiate module routing due to: Error: $injector:nomod Module 'routing' is not available

At the moment I am getting the error mentioned above. I think it's wierd that I am getting this error since I don't want to use 'routing' from Angular but just use angular for posting/getting data.

My Angular functions are split up in an module, service & controller file. On top of that I use the engine called 'EJS'. So this means that the HTML I list below looks a bit incomplete. This is because I include most of my HTML from a 'layout' file where the basic stuff like the Navigation bar is loaded.

HTML:

    <% include ../layout %>

        <body ng-app="clientModule">
            <div class="container" data-ng-cloak data-ng-app="clientModule" data-ng-controller="clientController">
                <form class="navbar-form navbar-left" role="search" method="POST" name="formClient">
                    <div class="row">
                        <div class="form-group">

                            <label for="">Client name</label>
                            <input type="text" class="form-control" placeholder="Please enter client name" name="clientName" ng-model="client.clientName" style="width: 100%" required>

                        </div>
                    </div>
                    <div>&nbsp;</div>
                    <div class="row">
                        <div class="form-group">

                            <label for="">Client address</label>
                            <input type="text" class="form-control" placeholder="Please enter client address" name="clientName" ng-model="client.clientAddress" style="width: 100%" required>

                        </div>
                    </div>
                    <div>&nbsp;</div>

                    <div class="row">
                        <div class="form-group">
                            <button type="button" class="btn btn-primary" ng-lick="createClient(client)">Create client</button>
                        </div>
                    </div>
                </form>
            </div>
        </body>



        <script src="/bower_components/angular/angular.js"></script>

        <script src="/bower_components/angular-route/angular-route.js"></script>
        <script src="../../controllers/clients/clientModule.js"></script>
        <script src="../../controllers/clients/clientService.js"></script>
        <script src="../../controllers/clients/clientController.js"></script>

Module:


var clientModule = angular.module('clientModule', []);

Service:


angular.module('clientModule').controller('clientService', clientService);


clientService.$inject = ['$http'];


function clientService($scope) {

    return {

        createClient : function (client) {

            return $http.post('/createClient',
                {
                clientName : client.clientName,
                clientAdress : client.clientAddress
            }
            );
        }
    };
}

Controller:


    angular.module('clientModule').controller('clientController', clientController);


        clientController.$inject = ['$scope', '$timeout', 'clientService'];


        function clientController($scope, $timeout, clientService) {

            $scope.client = {

                clientName : "",
                clientAddress : ""

            };

            $scope.client = function (client) {

                clientService.createClient(client).success(function (data) {

                   /* $timeout(function() {


                        alert("data posted successfully");

                    },3000) */
                });
            }
        }


NodeJS output:

    $ node server
    Server running on port: 1337
    GET /createClient 304 18.255 ms - -
    GET /stylesheets/bootstrap.min.css 304 6.576 ms - -
    GET /bower_components/bootstrap/dist/js/bootstrap.js 304 9.184 ms - -
    GET /bower_components/jquery/dist/jquery.min.js 304 10.352 ms - -
    GET /controllers/clients/clientService.js 304 4.351 ms - -
    GET /bower_components/angular/angular.js 304 6.103 ms - -
    GET /controllers/clients/clientModule.js 304 2.677 ms - -
    GET /bower_components/angular-route/angular-route.js 304 3.597 ms - -
    GET /controllers/clients/clientController.js 304 1.758 ms - -
    GET /bower_components/jquery/dist/jquery.min.map 304 1.767 ms - -
    GET /bower_components/angular-route/angular-route.js 304 0.733 ms - -
    GET /controllers/clients/clientModule.js 304 0.755 ms - -
    GET /controllers/clients/clientService.js 304 0.939 ms - -
    GET /controllers/clients/clientController.js 304 1.101 ms - -

jQuery routing file:

function clientRouteConfig(app) {

    this.app = app;
    this.routeTable = [];
    this.init();

}

clientRouteConfig.prototype.init = function() {

    var self = this;

    this.addRoutes();
    this.processRoutes();

}

clientRouteConfig.prototype.processRoutes = function() {

    var self = this;

    self.routeTable.forEach(function(route) {

        if(route.requestType == 'get') { 

           self.app.get(route.requestUrl, route.callbackFunction);

        }
        else if(route.requestType == 'post') { }
        else if(route.requestType == 'delete') { }

    });

}

clientRouteConfig.prototype.addRoutes = function() {

    var self = this;

    self.routeTable.push({

        requestType : 'post',
        requestUrl : '/createClient',
        callbackFunction : function(request, response) {

            response.render('../views/clients/createClient', { title: "Create client"});

        }

    });

    var self = this;

    self.routeTable.push({

        requestType : 'get',
        requestUrl : '/createClient',
        callbackFunction : function(request, response) {

            response.render('../views/clients/createClient', { title: "Create client"});

        }

    });


    self.routeTable.push({

        requestType : 'get',
        requestUrl : '/clients',
        callbackFunction : function(request, response) {

            response.render('../views/clients/clients', { title: "Clients"});

        }

    });

}


module.exports = clientRouteConfig;

Thanks in advance!

Upvotes: 1

Views: 373

Answers (1)

Mick
Mick

Reputation: 324

In my 'layout' file I called another app defined (old code) which caused the error. It is all fixed now :)!

Thanks all for cooperating.

Upvotes: 1

Related Questions