javascript - Issue - AngularJS Uncaught Error: [$injector:modulerr] -
am new angularjs. trying flow of sample application before start development of new app in project. below have tried.
index.html
<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <html ng-app="app"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <title>insert title here</title> <script src="lib/angular.min.js"></script> <script src="lib/angular-route.js"></script> <script type="text/javascript" src = "js/app.js"></script> </head> <body> <h1>student registration!</h1> <div ng-view></div> </body> </html>
registerstudent.html
<table> <tr> <td><input type="button" value="save" ng-click="save()"></td> <td>{{message}}</td> </tr> </table>
app.js
var app = angular.module("app", ['ngroute', 'app.services', 'app.controllers']); /**routing*/ app.config(['$routeprovider', function($routeprovider){ $routeprovider.when('/editstudent', { templateurl:'html/editstudent.html', controller:'studentreg' }); $routeprovider.when('/viewstudent', { templateurl:'html/viewstudent.html', controller:'studentreg' }); $routeprovider.when('/registerstudent', { templateurl:'html/registerstudent.html', controller:'studentreg' }); $routeprovider.otherwise({ redirectto: '/registerstudent' }); }]);
services.js
var app = angular.module('app.services', []); app.service('restservice', function(){ this.save=function(){ return 'saved'; }; });
controller.js
var app = angular.module('app.controllers', []); app.controller('studentreg', function($scope, restservice){ $scope.result=restservice.save(); $scope.save=function(){ console.log($scope.result); $scope.message=$scope.result; }; });
when tried run application, got below error.
uncaught error: [$injector:modulerr] http://errors.angularjs.org/1.5.0-rc.1/$injector/modulerr?p0=app&p1=error%3…2flocalhost%3a8080%2fenhancedstudentform%2flib%2fangular.min.js%3a20%3a421)
you forget load controller.js , services.js, that's guess. try after include app.js in index.html:
<script type="text/javascript" src = "js/controller.js"></script> <script type="text/javascript" src = "js/services.js"></script>
Comments
Post a Comment