Angular.JS:由于以下原因无法实例化模块路由:错误:$ injector:nomod模块'路由'不可用

时间:2015-11-20 12:21:49

标签: javascript jquery angularjs node.js

目前我收到上述错误。我认为我收到此错误很奇怪,因为我不想使用'路由'来自Angular但只是使用angular来发布/获取数据。

My Angular功能分为模块,服务和功能。控制器文件。 最重要的是,我使用名为' EJS'的引擎。所以这意味着下面的HTML I列表看起来有点不完整。这是因为我将大部分HTML包含在“布局”中。文件,其中加载了导航栏等基本内容。

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>
&#13;
&#13;
&#13;

模块:


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

服务:


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
            }
            );
        }
    };
}

控制器:


    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输出:

    $ 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路由文件:

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;

提前致谢!

1 个答案:

答案 0 :(得分:1)

在我的布局&#39;文件我调用了另一个定义的应用程序(旧代码),导致错误。现在全部修好了:))!

感谢大家的合作。

相关问题