2016-06-13 7 views
0

Ich baue eine angularjs-App, die von einer Login-Seite startet, aber wenn ich meine Login-Seite ausführe, bekomme ich unten Fehler in Konsole.

[$ Injektor: modulerr] Fehler beim Modul bookApp aufgrund instanziiert: Reference: 'wenn' nicht definiert ist bei Anonymous Funktion

PFB Die entsprechende files.Any Hilfe viel geschätzt im Voraus ist.

P.S. Bitte lassen Sie mich wissen, wenn weitere Informationen benötigt werden.

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

Antwort

2

routeProvider.when().when().when() funktioniert.

routeProvider.when();when();when() nicht. Semikolons sind wichtig.

+0

Vielen Dank für die Hilfe, es hat funktioniert !! –

Verwandte Themen