0
我正在構建一個從登錄頁面開始的angularjs應用程序,但是當我執行我的登錄頁面時,安慰。
[$注射器:modulerr]未能實例化模塊bookApp由於: 的ReferenceError: '當' 未定義 在匿名函數
PFB相關files.Any幫助是提前多appreciated.Thanks。
P.S.請讓我知道是否需要更多信息。
HTML:
<!doctype html>
<!--Mention the module name to <html> -->
<html ng-app="bookApp">
<head>
<title>Angular Assignment</title>
<style type="text/css">
@import "styles/style.css";
</style>
<script src="lib/Angular/angular.js"></script>
<script src="lib/Angular/angular-route.js"></script>
<script src="js/controllers.js"></script>
<script src="js/app.js"></script>
</head>
<body>
<center>
<!--include header.html -->
<div ng-include="'Header.html'"></div>
</center>
<!-- Add the required controller to this div.
Associate the models for username and password.-->
<div align="center" ng-controller="LoginCtrl">
<h2> Login </h2>
<div class="LoginFormDiv">
<table border="0">
<tr>
<td> Username </td>
<td>:
<input ng-model="username" class="input" placeholder="Enter Username"/>
</td>
</tr>
<tr>
<td> Password</td>
<td>:
<input ng-model="password" class="input" placeholder="Enter Password"/>
</td>
</tr>
<tr>
<td colspan="2">
<!-- On click of the button, call validate(user) method declared in controller-->
<input type="submit" class="button" value="Login" ng-click="validate()"/>
</td>
</tr>
</table>
</div>
</div>
<!-- include footer.html -->
<center>
<div ng-include="'Footer.html'"></div>
</center>
</body>
</html>
Controller.js
var Controllers = angular.module('Controllers', ['ngRoute']);
Controllers.controller('LoginCtrl', ['$scope', '$location', '$http', '$rootScope',
function($scope, $location, $http, $rootScope) {
alert("I am in LoginCtrl")
$scope.validate = function() {
alert("I am in validate function");
$http.get('data/roles.json').success(function(data) {
$scope.roles = data;
});
var count = 0;
angular.forEach($scope.roles, function(role) {
if ($scope.username == role.username && $scope.password == role.password) {
alert("login successful");
count = count + 1;
if ($scope.roles == "student") {
$location.path("/home/student");
} else {
$location.path("/home/librarian");
}
} else if (count != 1) {
alert("Please provide valid login credentials");
$location.path("/main")
}
});
}
}]);
app.js
var bookApp = angular.module('bookApp', ['Controllers', 'ngRoute']);
bookApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.when('/main', {
templateUrl : 'Login',
controller : 'LoginCtrl'
}).when('/home/student', {
templateUrl : 'ViewBooks_Student.html',
controller : 'BookListCtrl_Student'
});
when('/home/librarian', {
templateUrl : 'ViewBooks_Librarian.html',
controller : 'BookListCtrl_Librarian'
});
when('/issue/:bookId', {
templateUrl : 'IssueBook.html',
controller : 'IssueBookCtrl'
});
when('/return/:bookId', {
templateUrl : 'ReturnBook.html',
controller : 'ReturnBookCtrl'
});
otherwise({
redirectTo : '/main'
});
}]);
非常感謝您的幫助,它的工作! –