Angular.JS:由于以下原因无法实例化模块路由:错误:$ injector:nomod模块“路由”不可用
目前我收到上面提到的错误。 我觉得这很奇怪,我得到这个错误,因为我不想使用Angular的'路由',只是使用angular来发布/获取数据。
我的angularfunction被分割成模块,服务和控制器文件。 最重要的是,我使用了名为“EJS”的引擎。 所以这意味着下面的HTML列表看起来有点不完整。 这是因为我包含了大部分的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> </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> </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>
模块:
var clientModule = angular.module('clientModule',[]);
服务:
angular.module('clientModule')。controller('clientService',clientService); clientService。$ inject = ['$ http']; 函数clientService($ scope){ 返回{ createClient:function(client){ 返回$ http.post('/ createClient', { clientName:client.clientName, clientAdress:client.clientAddress } ); } }; }
控制器:
angular.module('clientModule')。controller('clientController',clientController); clientcontroller。$ inject = ['$ scope','$ timeout','clientService']; 函数clientController($ scope,$ timeout,clientService){ $ scope.client = { 客户名称 : ””, clientAddress:“” }; $ scope.client = function(client){ clientService.createClient(client).success(function(data){ / * $ timeout(function(){ 警报(“数据张贴成功”); },3000)* / }); } }
NodeJS输出:
$节点服务器 运行在端口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路由文件:
函数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;
提前致谢!
在我的“布局”文件中,我调用了另一个定义的应用程序(旧代码),这导致了错误。 现在都是固定的:)!
感谢所有的合作。